I ran into this before. I haven't used asEagerSingleton but only singleton scope and I assume the behavior is the same.

The singleton nature is only on the binding. So you defined MyInterface as a singleton, and said nothing about MyImpl.

So injector.getInstance(MyInterface.class) == injector.getInstance(MyInterface.class);

But
injector.getInstance(MyImpl.class) != injector.getInstance(MyImpl.class);

What you should do is define MyImpl as a singleton if you really only want one MyImpl. Then I believe it is irrelevant whether or not MyInterface is in Singleton because there's only one MyImpl it can get, but I normally define both in singleton.

Jason

On 9/10/2010 3:58 PM, Brian Pontarelli wrote:
I have an project that is using 1.0 still and I found an odd behavior that I
wanted to ask about and see if it is different in 2.0. The issue is when
asking for different sides of a binding. Here's my binding code:

    bind(MyInterface.class).to(MyImpl.class).asEagerSingleton();


The interesting thing is that these two lines of code return different 
instances:

    injector.getInstance(MyInterface.class);
    injector.getInstance(MyImpl.class);


Is this expected behavior? If not, does this behavior exist in 2.0? If so, can
someone explain to me why this is expected?

Thanks,
-bp

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

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

Reply via email to