Benefits of IOC (Dependency Injection) are as follows:
1 Minimizes the amount of code in your application. With IOC containers you do
not care about how services are created and how you get references to the ones
you need. You can also easily add additional services by adding a new
constructor or a setter method with little or no extra configuration.
2 Make your application more testable by not requiring any singletons or JNDI
lookup mechanisms in your unit test cases. IOC containers make unit testing and
switching implementations very easy by manually allowing you to inject your own
objects into the object under test.
3 Loose coupling is promoted with minimal effort and least intrusive
mechanism. The factory design pattern is more intrusive because components or
services need to be requested explicitly whereas in IOC the dependency is
injected into requesting piece of code. Also some containers promote the design
to interfaces not to implementations design concept by encouraging managed
objects to implement a well-defined service interface of your own.
4 IOC containers support eager instantiation and lazy loading of services.
Containers also provide support for instantiation of managed objects, cyclical
dependencies, life cycles management, and dependency resolution between managed
objects etc.