-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
31 lines (22 loc) · 1.37 KB
/
README
File metadata and controls
31 lines (22 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
This is a very simple dependency injection package built towards auto-instantiating classes and injecting them into other classes in a managable manner. Auto-instantiation syntax is a clone of Spring's annotation formatting, example:
@Controller
public class MyController implements MyControllerInterface { }
This will create an instance of MyController and use that instance whenever a value of MyController or MyControllerInterface is needed. Alternately, you can use @Repository, @Service, and @Component (as per Spring), though there's no difference between the functionality at this point.
For dependency injection, the injection acts very much like Guice minus the configuration files, example:
@Component
public class MyConfig implements SomeServiceConfig { }
@Service
public class MyService implements SomeService {
private SomeServiceConfig config;
@Inject
public MyService( SomeServiceConfig config ) {
this.config = config;
}
}
This allows for classes that can be injected into safely but still allows for unit-testing and auto-instantiation. Note that the ContextListener must be loaded (in the web.xml file) for any of the injection to take place:
<web-app>
<listener>
<listener-class>com.villainsoft.core.injection.utils.ContextListener</listener-class>
</listener>
<!-- other webappy stuff here -->
</web-app>