How about removing the @Inject annotation from the B field of C and adding c.b = b after the injectMembers call?
--tim On Tue, Sep 7, 2010 at 5:17 PM, Mauricio <[email protected]> wrote: > I'm using Guice on a restful web service. I'm binding some object > instances as RequestScoped. One of these objects is a Runnable object > that I want to run inside a Thread. The problem is that the object > being inside a thread, Guice fails to inject some dependencies by > throwing an OutOfScopeException. The Runnable object and its > dependencies are injected well, but I have some object that I'm > injecting manually inside the thread by Injector.injectMembers, > because I can't control its creation. > > Something like : > > //A is RequestScoped > Class A implements Runnable{ > //B is RequestScoped > B b; > C c; > > @Inject > Injector injector > > @Inject > A(B b){ > this.b = b > } > ... > public void run(){ > //c is an instance of C created before > injector.injectMembers(c) > } > > } > > Class C{ > @Inject > B b; > ... > } > > Since the injection occurs inside the thread Guice isn't able to > inject dependencies throwing the mentioned OutOfScopeException. > What would be the workaround, knowing that I must inject the instance > manually after instantiating all other objects. > > Any help would be greatly appreciated. > > -- > 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]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > -- 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.
