On Sep 15, 11:51 am, Sam Berlin <[email protected]> wrote:
> That's one way of doing it. I suppose it'd work, too, so long as provideFoo
> wasn't marked as a singleton (because we do want Foo to change through its
> lifetime). But, it has the sort-of-bad behavior of effectively creating two
> Providers for Foo, the ProviderMethod provider & the real Provider.
One thing to keep in mind - whenever you bind a Provider<Foo> and then
inject a Provider<Foo>, you get different provider instances. To
illustrate:
final FooProvider a = new MyFooProvider();
Injector injector = Guice.createInjector(new AbstractModule() {
public void configure() {
bind(Foo.class).toProvider(a);
}
});
Provider<Foo> b = injector.getProvider(Foo.class);
assertFalse(a == b);
assertFalse(b instanceof FooProvider);
With scopes, the difference is even more pronounced. If we were to
scope the Foo binding in singleton scope, repeated calls to a.get()
would still return different instances.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---