|
Project Information
Featured
Downloads
|
Guice Integration for StripesStripes-guicer is early alpha software. Download and use at your own risk, and please leave bug reports! What Do I Get with stripes-guicer?Constructor, Field, and Method Injection in Stripes ActionBean, ActionBeanContext, and Interceptors(Constructor injection is only available in ActionBeans.) For example, if MyActionBean relies on MyService: public class MyActionBean implements ActionBean {
private MyService myService;
private MyService otherService;
@Inject
public MyActionBean( MyService myService ) {
this.myService = myService;
}
@Inject public void setService(@MyAnnotation MyService service){
this.otherService = service;
}
}ActionBeanContext injection: public MyActionBeanContext extends ActionBeanContext {
...
@Inject public void setService(MyService service) { ... }
}Interceptor injection. This example will close MyService after each request: @Intercepts(LifecycleStage.RequestComplete)
public class MyInterceptor implements Interceptor {
@Inject private MyService service;
public Resolution intercept(ExecutionContext executionContext) {
service.close();
}
}
Request scope bindingsThis Guice module will give one MyService per request, no matter where it is injected: public class MyModule extends AbstractModule {
protected void configure() {
bind(MyService.class)
.to(MyServiceImpl.class)
.in(ServletScopes.REQUEST);
}
}How Do I Get Guicing?Prerequisites:
Under Stripes' <filter> tag:
<!-- For Guice -->
<init-param>
<param-name>Interceptor.Classes</param-name>
<param-value>com.googlecode.stripesguicer.GuiceInterceptor</param-value>
</init-param>
<init-param>
<param-name>ActionResolver.Class</param-name>
<param-value>com.googlecode.stripesguicer.GuiceActionResolver</param-value>
</init-param>
<init-param>
<param-name>Guice.ModuleClasses</param-name>
<param-value>
<!-- put your guice modules here, comma separated -->
my.example.InjectorModule
</param-value>
</init-param>
<!-- end -->Notes:
protected ActionBean makeNewActionBean(Class<? extends ActionBean> type,
ActionBeanContext context) {
return GuiceInjectorFactory.makeGuicedActionBean(type, context);
}
|