Java Reference
In-Depth Information
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;
}
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,
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:
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