On 7 Mar 2013, at 15:18, Sam Berlin wrote:

> While writing, I considered notifying a ProvisionListener to still be "part 
> of the construction".  I remember wondering about this specific part (whether 
> the finally should be inside or outside), and ended up settling on "outside". 
>  But, I can't really give you any concrete reason of why I settled on that.
> 
> There's a few different places we notify provision listeners (and I added one 
> more internally, to notify on toInstance/bindConstant bindings too... still 
> waiting on the sync-stuff to be fixed to push that out), so I'd have to 
> analyze all of them to really figure it out.

Thanks, I've logged this under 
http://code.google.com/p/google-guice/issues/detail?id=743

I'll also run some of my local ProvisionListener-based projects with a patched 
build to see what happens.

> sam
> 
> On Thu, Mar 7, 2013 at 10:12 AM, Stuart McCulloch <[email protected]> wrote:
> On 7 Mar 2013, at 13:39, [email protected] wrote:
> 
>> Hummm.... It doesn't seem to work! Maybe I'm missing something?
> 
> Unfortunately not - by tracing through your test I can see it still hits the 
> issue with the constructionContext reference since that's only removed after 
> all the provisioning hooks are done. I'm wondering whether it makes sense to 
> move the reference removal into a finally block in the provision method - ie. 
> after custom injection and injection listeners, but before all the provision 
> hooks have completed. This fixes your testcase and all the unit tests still 
> pass, but I'd need to do more thorough investigation into whether this could 
> cause problems elsewhere. (Would appreciate Sam's input since he wrote the 
> ProvisionListener feature.)
> 
> diff --git a/core/src/com/google/inject/internal/ConstructorInjector.java 
> b/core/src/com/google/inject/internal/ConstructorInjector.java
> index e71a25a..8f86db5 100644
> --- a/core/src/com/google/inject/internal/ConstructorInjector.java
> +++ b/core/src/com/google/inject/internal/ConstructorInjector.java
> @@ -94,7 +94,6 @@ final class ConstructorInjector<T> {
>          });
>        }
>      } finally {
> -      constructionContext.removeCurrentReference();
>        constructionContext.finishConstruction();
>      }
>    }
> @@ -125,6 +124,8 @@ final class ConstructorInjector<T> {
>            : userException;
>        throw errors.withSource(constructionProxy.getInjectionPoint())
>            .errorInjectingConstructor(cause).toException();
> +    } finally {
> +      constructionContext.removeCurrentReference();
>      }
>    }
>  }
> 
>> https://gist.github.com/electrotype/5108107
>> 
>> I use :
>> 
>>         <dependency>
>>             <groupId>org.sonatype.sisu</groupId>
>>             <artifactId>sisu-guice</artifactId>
>>             <version>3.1.3</version>
>>         </dependency>
>> 
>>         <dependency>
>>             <groupId>org.sonatype.sisu.inject</groupId>
>>             <artifactId>guice-assistedinject</artifactId>
>>             <version>3.1.3</version>
>>         </dependency>
>> 
>> Thank you.
>> 
>> 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] 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].
>>> 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.
>>>  
>>>  
>> 
>> 
>> -- 
>> 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.
>>  
>>  
> 
> 
> -- 
> 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.
>  
>  
> 
> 
> -- 
> 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.
>  
>  

-- 
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.


Reply via email to