Thanks Stuart. You pointed me the correct way to be. Many thanks!
在 2013年1月9日星期三UTC+8下午9时00分21秒,Stuart McCulloch写道:
>
> On 9 Jan 2013, at 09:20, Michael wrote:
>
> > Hi All,
> >
> > I created an annotation named "Validate"
> >
> > @Retention(RetentionPolicy.RUNTIME)
> > @Target(ElementType.METHOD)
> > public @interface Validate {
> > Class<? extends MethodInterceptor>[] value();
> > }
> >
> > And defined it before a method
> > @Validate({OneInterceptor.class, TwoInterceptor.class})
> > public void doPost(HttpServletRequest req, HttpServletResponse resp)
> {
> > //do something
> > }
> >
> > OneInterceptor implements MethodInterceptor {.....} TwoInterceptor
> implements MethodInterceptor{....}
> >
> > So I want to know is there a possible to bind interceptors within a
> Module like this ? Many thanks!
>
> One option would be to have a ValidateMethodInterceptor implementation
> bound in your module that gets the Validate annotation from the reflected
> method, ie. methodInvocation.getMethod().getAnnotation(Validate.class) -
> and then delegates to the listed method interceptors. If you want the
> delegated method interceptors injected (as opposed to clazz.newInstance)
> then you'll need to add a @Inject'd field/setter to
> ValidateMethodInterceptor for the injector and arrange for the
> ValidateMethodInterceptor instance to be injected with
> binder.requestInjection(...) - then you can call
> injector.getInstance(clazz) for each interceptor at delegation time.
>
> --
> Cheers, Stuart
>
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/nju5lWvrmOcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.