Comment by [email protected]:

Here is how I've used it;

I had to have providers for IFoo which needed to return different impl old vs new,

in my module, I added providers like

@Provides @Named("old")
IFoo getFoo() {
.
}


and


@Provides @Named("new")
IFoo getFoo() {
.
}


On injector site, couple of ways to get desired IFoo

* Using constructor

@Inject
MyObj(@Named("old") IFoo foo) {
this.foo = foo;
}

* or explicitly using injector to get desired instance

IFoo foo = injector.getInstance(Key.get(IFoo.class, Names.named("old")));

injector is of course injected in calling class :)

Hope this helps.

For more information:
http://code.google.com/p/google-guice/wiki/ProvidesMethods

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" 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-dev?hl=en.

Reply via email to