I have a class (WindowedCounter) which is creating using assisted injection. I need to inject a factory for this class into a method interceptor. Now a method interceptor can only be bound to a concrete instance. So my question is how to do this neatly.
The code below is what I came up with so far. I create a Factory Provider for the factory and use it to get a factory instance in the module itself. Which is then bound to both the class and used to get an instance to bind to the interceptor. However FactoryProvider class is depreciated as of Guice 3.0.
What is the Guice 3.0 way of doing this?
Can I inject instances in a module?
Provider<WindowedCounterFactory> wCountFactoryProvider = FactoryProvider.newFactory(WindowedCounterFactory.class, WindowedCounter.class);
bind(WindowedCounterFactory.class).toProvider(wCountFactoryProvider);
WindowedCounterFactory wCountFactory = wCountFactoryProvider.get();
bindInterceptor(Matchers.any(), Matchers.annotatedWith(RateLimited.class), new RateLimitingInterceptor(wCountFactory));