With EJB3 interceptor model & JSR 330, DI has established further ground with Sun Microsystems likeness towards it.
DI can be defined as:
"DI is a special form of IOC (Inversion of Control) and design paradigm flexible enough to allow external dependencies to be configured/applied dynamically to software architecture."
Martin Fowler has identified 3 types of DI:
- Type 1 or interface injection, in which the exported module provides an interface that its users must implement in order to get the dependencies at runtime
- Type 2 or setter injection, in which the dependent module exposes a setter method that the framework uses to inject the dependency
- Type 3 or constructor injection, in which the dependencies are provided through the class constructor
Available Popular Solutions in Java for DI
- EJB3 Interceptors (Standardized Model by Sun)
- JSR 330: Dependency Injection for Java (recently finalized for future Java releases, led by Google, SpringSource, Sun)
- Spring framework (one of the earliest framework to promote DI)
- Google Guice (pronounced as "juice")
- Apache HiveMind (Services & Configuration Microkernel)
- Apache Tapestry IOC
- JBoss Microcontainer
- Plexus
- Reduction of dependent code
- Configuration Flexibility
- Excessive usage can lead to complicated/hard-to-debug code
- Difficult to understand complex DI usage because of dynamic injection