Search This Blog

Monday, September 10, 2007

Types of Dependency Injections.

1 Type 1 IOC also called Interface Injection

o In Type 1 IOC the injection is done though an interface. The interface will define the injection method and the implementation class has to implement this interface and provide concrete implementation for the injection method.

2 Type 2 IOC also called Setter Injection

o In Type 2 IOC the injection is done via a setter method. Type 2 IOC uses setter methods to get the dependent classes it needs.

3 Type 3 IOC also called Constructor Injection.

o In Type 3 IOC implementing class defines a constructor to get all its dependents. The dependent classes are defined in the constructor arguments.

Spring supports only Constructor based injection and setter based injection.

Spring recommends setter-based injection over constructor-based injection as multiple constructors can make the bean huge and unmanageable.

No comments: