Status: New
Owner: ----

New issue 751 by [email protected]: Guice is injecting members when binding an instance [bind().toInstance()].
http://code.google.com/p/google-guice/issues/detail?id=751

Hi,

I'm not sure if this is a bug but at least is worth to talk about it.

I noticed that when we perform a bind().toInstance() and the instance is an annotated class with @Inject etc, Guice will try to fill in those members.

My question is: is that suppose to happen? For me it was a surprise. Imagine the following use case:

You're running an application service where each service have their own dependency Guice instance and each of them publish some reference to a shared JNDI space.

The you need a reference to that service in another and you try to bind that service interface using bind().toInstance(). Guice will try to fill in the members that are already filled in. Well this is an issue, but not the only one. Imagine that each service run in it's classloader and inject members that are only visible in their context. It will fail saying that no implementation is bound (in fact that isn't) by the service trying to "re-inject" all the members again.

Well, again, I'm not saying it is a bug, but if it's not I think it's worth documenting about this behaviour.

I managed to to what I want using a provider that always returning the same instance. Is there any other way to do this?

Regards,

Rui


--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to