Quote

We are what we repeatedly do. Excellence, therefore,is not an act but a habit.

Aristotle

Wednesday, January 6, 2010

Spring Framework Dependencies

Injecting Dependencies(DI) : The basic principle of the the Di is that objects define their dependencies that is to say the other objects they work for only through constructor arguments, arguments to a factory method or properties which are set on the object instance after it has been constructed or returned from a factory method.

It is the job of the container to inject those dependencies when the bean is created which is inverse of what happens and hence the name IoC. In IoC bean itself is in control of instantiating ot locating its dependencies on its own using direct construction of classes or something else.
DI is of two types Constructor Injection and Setter Injection.

Constructor-based DI is effected by invoking a constructor with a number of arguments, each representing a dependency.

Setter-based DI is realized by calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.

No comments:

Post a Comment