4 ms·
They are two different tools needed for two different jobs. Constructor injection is for mandatory dependencies, setter injection is for optional dependencies.
by tigershark 10y ago
They are two different tools needed for two different jobs.
Constructor injection is for mandatory dependencies, setter injection is for optional dependencies.
If you are writing a plugin application and some modules are optional then you cannot use constructor injection because when the optional module is not present you cannot start your whole application.
In 99% of the cases obviously constructor injection is the way to go.