Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
One of the biggest selling points of DI over dependency lookup as a mechanism for achieving IoC is that your beans do not need to be aware of the implementation of the container that is managing them. To a bean that uses constructor injection, the Spring container is the same as the container provided by PicoContainer. However, in certain circumstances, you may need a bean that is using DI to obtain its dependencies so it can interact with the container for some other reason. An example of this may be a bean that needs access to the BeanFactory to automatically configure a shutdown hook for you. In other cases, a bean may wish to know its name so it can perform some additional processing based on this name.
|