Saturday, March 19, 2011

Spring : What is IoC or DI ?

It is the process whereby objects define their dependencies, that is, the other objects they work with. The container then injects those dependencies when it creates the bean. This process is fundamentally the inverse, so called Inversion of Control.

The IoC Container:
The IoC container is an implementation of BeanFactory interface. Further we have ApplicationContext and WebApplicationContext interfaces and also it ready to use implementations specifically suited for enterprise application development.
The most commonly used form of IoC container is the ApplicationContext Implementation.

The container gets its instructions on what objects to instantiate , configure and assemble by reading configuration metadata.

Click here to see various methods of dependency injection. But to start with we can first see a simple example of DI here.
The need for DI / IoC gets clearer if we see this example.

    No comments:

    Post a Comment

    Chitika