java - Injecting method interceptors in Guice -


i've searched on web , (including) google suggests using requestinjection() still don't understand how use it. have class implements method interceptor:

public class cacheinterceptor implements methodinterceptor {     private ilocalstore localstore;     private iremotestore remotestore;     private cacheutils cacheutils;      public cacheinterceptor() {     }    @inject     public cacheinterceptor(ilocalstore localstore, cacheutils cacheutils, iremotestore remotestore) {     this.localstore = localstore;     this.cacheutils = cacheutils;     this.remotestore = remotestore;     } } 

and have 3 classes extends abstractmodule.

public class cacheutilmodule extends abstractmodule {     @override     protected void configure() {         bind(cacheutils.class);     } }  public class localcachingmodule extends abstractmodule {     @override     public void configure() {         bind(ilocalstore.class).to(localstore.class);     } }  public class rediscachingmodule extends abstractmodule {     @override     protected void configure() {         bind(iremotestore.class).to(remotestore.class);     } } 

and did following binding interceptor

public class requestscopedcachingmodule extends abstractmodule {      @override     public void configure() {         install(new cacheutilmodule());         install(new localcachingmodule());         install(new rediscachingmodule());         methodinterceptor interceptor = new cacheinterceptor();         requestinjection(interceptor);         bindinterceptor(matchers.any(),   matchers.annotatedwith(cacheable.class),             interceptor);     }  } 

so basically, want inject localstore, remotestore, , cacheutils in methodinterceptor own implementation mapped out in 3 modules. didn't work. guess confused requestinjection(). in documentation, requestinjection this

upon successful creation, injector inject instance fields , methods of given object.

but specify mapping between interface , implementation class? how can wanted work?

requestinjection inject fields , methods - won't invoke constructor , doesn't know @inject annotations on constructor. if add @inject of fields code should work expect.


Comments