Java Reference
In-Depth Information
Download email_33/src/stripesbook/action/BaseActionBean.java
public abstract class BaseActionBean implements ActionBean {
@Inject protected AttachmentDao attachmentDao;
@Inject protected ContactDao contactDao;
@Inject protected FolderDao folderDao;
@Inject protected MessageDao messageDao;
@Inject protected UserDao userDao;
}
Download email_33/src/stripesbook/ext/MyActionBeanContext.java
public class MyActionBeanContext extends ActionBeanContext {
@Inject protected FolderDao folderDao;
@Inject protected UserDao userDao;
}
That's all there is to it. To inject dependencies on other Stripes objects,
we'd use the same technique as we did for Spring on page 265 : subclass
the default factory, retrieve the object, and inject the dependencies.
Instead of this:
SpringHelper.injectBeans(object, context);
we'd use the following:
GuiceInterceptor.getInjector().injectMembers(object);
13.5
Another Interceptor Example: Ensuring Login
The Guice interceptor example was pretty cool in terms of implementing
Guice support, but it was rather light on the actual interceptor code:
Download email_33/src/stripesbook/ext/guice/interceptor/GuiceInterceptor.java
package stripesbook.ext.guice.interceptor;
@Intercepts(LifecycleStage.ActionBeanResolution)
public class GuiceInterceptor
implements Interceptor, ConfigurableComponent
{
/ * ... * /
public Resolution intercept(ExecutionContext context)
throws Exception
{
injector.injectMembers(context.getActionBeanContext());
Resolution resolution = context.proceed();
injector.injectMembers(context.getActionBean());
return resolution;
}
}
 
 
 
Search WWH ::




Custom Search