EZinjector is a simple no-configuration dependency injection framework.
Consider the quintessential Data Access Object pattern:
public interface Dao {...}
public class SomeDaoImpl implements Dao {...}
public class BusinessObject {
private Dao dao = new SomeDaoImpl();
...
}
Clearly the BusinessObject class is tightly coupled with the Dao implementation. To decouple these classes with EZinjector we simply annotate the Dao reference in the BusinessObject class:
public class BusinessObject {
@Dependency
private Dao dao;
...
}
Now the BusinessObject class is decoupled from the Dao implementation. There is no additional code needed--you do not have to annotate the implementation class or create a configuration file. The framework will inject an instance of SomeDaoImpl automatically.
How is this possible? How does the framework know which implementation to inject when it has not been specified? EZinjector was designed for situations where the implementation has already been specified, implicitly. For example, consider an application that has two deployment scenarios: test and production. The test deployment has stubbed out implementations and the production deployment has the real implementations, but in each case there is only one implementation available at runtime--the one chosen by the build process in creating the deployable. In this example EZinjector does not need to know which implementation to inject; it injects whatever is available.
Please see the User Guide for more information.