
上QQ阅读APP看书,第一时间看更新
Advantages of the constructor-based DI
The following are the advantages of a constructor-based DI in your Spring application:
- It's suitable for mandatory dependencies. In a constructor-based DI, you can be sure that the object is ready to be used the moment it is constructed.
- The code structure is very compact and clear to understand.
- When you need an immutable object then, through constructor-based dependency, you can ensure you get the immutable nature of the object.