I'm new to Guice, and I'm using injection within an interceptor, with
requestInjection() in my module.

The interceptor is being called just fine, so my module appears to be
good.  The problem is that @Inject is always creating a new object
using the constructor for that object instead of injecting the
original pre-initialized one.  What am I missing here?

public class TestInterceptor implements MethodInterceptor {
  @Inject MyObject obj; // always a newly-created object

  public Object invoke(...) { obj.doSomething(); ... }
}

public class TestImpl implements Test {
  @Inject MyObject obj;

  public TestImpl() {
    Injector injector = Guice.createInjector(new TestModule());
    obj = injector.getInstance(MyObject.class);
    obj.init(); // I want access to this already initialized object in
the interceptor
  }
}

Thanks.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to