October 2018
Intermediate to advanced
590 pages
15h 5m
English
For those mandatory dependencies, we should always inject them through constructors. In this way, after creation, the instance will be fully initialized and the dependencies will be read-only. No one can tempt you with dependencies anymore.
For those optional dependencies, we can inject them through setters/methods.
As for field-based injection, we should avoid using it. Spring makes the field injection by using Java Reflection, and it is considered to be harmful to use field injection. As a matter of fact, it should be avoided for the following reasons:
Read now
Unlock full access