title: Injecting method interceptors in Guice
body: <p>I've searched all over the web for it and everyone (including) google suggests using <code>requestInjection()</code> but I still don't understand how to use it. I have a class that implements Method Interceptor:</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>And I have 3 classes that extends <code>AbstractModule</code>.</p>
  
  <pre><code>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);
      }
  }
  </code></pre>
  
  <p>And I did the following for binding the interceptor </p>
  
  <pre><code>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);
      }
  
  }
  </code></pre>
  
  <p>So basically, I want to inject the localStore, remoteStore, and cacheUtils in my MethodInterceptor with my own implementation mapped out in my 3 modules. But this didn't work. I guess I am just confused with requestInjection(). In the documentation, requestInjection does this</p>
  
  <blockquote>
    <p>Upon successful creation, the Injector will inject instance fields and methods of the given object.</p>
  </blockquote>
  
  <p>But where do we specify the mapping between the interface and the implementation class? How can I get what I wanted to do to work?</p>