What are the different scenarios to use Setter and Constructor based injection in Dependency Injection (DI) design pattern?

We use Setter injection to provide optional dependencies of an object. Constructor injection is used to provide mandatory dependency of an object.

In Spring IoC, Dependency Injection is heavily used. There we have to differentiate between the scenario suitable for Setter based and Constructor based dependency injection.

Leave a Reply

Your email address will not be published. Required fields are marked *