Excellent, thanks! I think this is exactly what I need.
On Wednesday, March 6, 2013 9:59:28 PM UTC-5, Stuart McCulloch wrote: > > You might want to look at the ProvisionListener hook that's been added in > trunk: > > https://groups.google.com/d/msg/google-guice/wRPmutuepmM/5TbMHMm3wJUJ > > http://code.google.com/p/google-guice/issues/detail?id=78#c16 > > It lets you intercept after an instance has been completely provisioned > (ie. fully injected, including circular proxies) but before it's returned > from the injector to the caller. > > On 7 Mar 2013, at 02:44, [email protected] <javascript:> wrote: > > First, here's a unit test for the issue > :https://gist.github.com/electrotype/5105100 > > I'm trying to use a listener to call an "init()" method on my classes when > they are constructed. I also use AssistedInject factories. > > I think the problem is that in * > com.google.inject.internal.ConstructorInjector#construct(...)* , this > code is supposed to prevent infinite loops : > > > T t = constructionContext.getCurrentReference(); >> if (t != null) { >> return t; >> } >> > > To remove the "current reference", *removeCurrentReference()* is called > in the *finally* clause : > > > } finally { >> constructionContext.removeCurrentReference(); >> } >> > > The problem is that before this removal method is called, *the listeners > are called* : > > membersInjector.notifyListeners(t, errors); >> > > > It seems that this is the root of my issue, because the reference still > exists when my "init()" methods are called (via the listeners), so when > they try to create an instance using the factories, they get the cached > instance instead of a new one! > > Does this mean I can't use a listener to call my init() methods? Are there > some workarounds? > > Thanks in advance! > > > > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > To post to this group, send email to [email protected]<javascript:> > . > Visit this group at http://groups.google.com/group/google-guice?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
