Status: New
Owner: ----

New issue 802 by [email protected]: Unexpected interaction between InjectionListener and singleton bindings
http://code.google.com/p/google-guice/issues/detail?id=802

I apologize if this issue is already known. I only found 2 issues mentioning the InjectionListener and none seemed related to the following.

Description of the issue:

It seems that instantiating singleton instances within the scope of InjectionListener.afterInjection() causes Guice to associate an instance to a type instead of associating it to a key (type and annotation).

The attached application InjectorListenerWithSingletons attempts to illustrate the issue:

* Bind an annotated interface to an implementation as a singleton.
* Bind the same interface with a different annotation to the same implementation as a singleton. * Retrieve instances of both annotated interfaces and compare them (using ==) * Repeat the same steps but this time instantiating the annotated interfaces within an InjectionListener.afterInjection()

Steps to reproduce:
1. Execute InjectorListenerWithSingletons as is with java assertions enabled. It should fail with error "KEY_1 and KEY_2 should be different". 2. Comment out line 63 (p1.get()) or line 64 (p2.get()), or both, and re-run the application. This time the test should pass.

Let me know if there is a fundamental flaw in the design of the test, or if you need more details or additional tests.

Thanks for your time.

Attachments:
        InjectorListenerWithSingletons.java  3.0 KB

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.

Reply via email to