|
Project Information
Featured
Downloads
Links
|
KouInjectKouInject is a simple but powerful dependency injection framework for Java, with the goal of being easy to use. The framework is built on the standard for dependency injection in Java (JSR-330), with many enhancements. Latest news:
Features:
Sneak peakThis is just a quick preview of some of the capabilities of KouInject. Head over to the user guide for all the details. You need an injector to load the beans. It's created like this: Injector injector = new DefaultInjector("com.zoo.app");The injector will scan the package com.zoo.app and all sub-packages for beans. All beans annotated with @Component will be available for injection. Like this: @Component
public class MonkeyService {
}To get MonkeyService injected somewhere you have to use @Inject: @Component
public class MonkeyController {
@Inject
private MonkeyService monkeyService;
}Perhaps that MonkeyController also needs a MonkeyValidator, but the validator requires extra runtime configuration to be setup correctly. In that case, you can use a factory, like this: @Component
public class Factory {
@Produces
public MonkeyValidator createMonkeyValidator() {
MonkeyValidator monkeyValidator = new MonkeyValidator();
// Do advanced configuration ...
return monkeyValidator;
}
}MonkeyValidator will be available for injection, just like MonkeyService. Beans are loaded on demand, so nothing happens until you ask the injector for at least one bean. You would typically ask for a bean that initializes the application, like creating the user interface and starting services. Like this: ZooClient zooClient = injector.getBean(ZooClient.class); Requirements:
Created by Christian Ihle |