CanDI Pattern Tutorial: SetServlet
The SetServlet demonstrates the four Java Injection
patterns by injecting the services and resources and
displaying their values in tables.
Click on the 'SetServlet blue' link, the
'SetServlet red' link, and the 'SetServlet' link
to check that both servlets share the same MyService
instance
Demo Links
Service Pattern
Binding | Value
|
---|
@Inject MyService | MyServiceBean[MyStartupBean: initial value]
|
Resource Pattern
Binding | Value
|
---|
@Red MyResource | RedResourceBean[red resource]
|
@Blue MyResource | BlueResourceBean[blue resource]
|
Plugin/Extension Pattern
- BlueResourceBean[blue resource]
- GreenResourceBean[default]
- RedResourceBean[red resource]
- StartupResourceBean[MyStartupBean: initial value]
Startup Pattern
Binding | Value
|
---|
@Inject StartupResourceBean | StartupResourceBean[MyStartupBean: initial value]
|
Demo Architecture
SetServlet Code
public class SetServlet extends HttpServlet {
// service pattern
private @Inject MyService _service;
// resource pattern
private @Red MyResource _redService;
private @Blue MyResource _blueService;
// plugin/extension pattern
private @Any Instance<MyResource> _resources;
// startup pattern
private @Inject StartupResourceBean _startupResource;
...
}