you could bind each pair in a private module and expose them annotated:
class my Module extends PrivateModule {
bind(IBar.class).to(AdminBar.class);
bind(IFoo.class).annotatedWith(...).to(AdminFoo.class);
expose(IFoo.class).annotatedWith(...);
}
This way the Foo can have the Bar object injected without annotation and
will always get the one that is binded in the same private module than
the actual IFoo implementation.
On 05/16/2014 12:58 PM, Jochen Wiedmann wrote:
Hi,
I've got several components, which look roughly like this
public class Foo implements IFoo {
private @Inject Bar bar;
...
}
In my application, I am using several instances of IFoo with different
values for @Named. Like this:
public class App {
private @Inject @Named(value="admin") adminFoo;
private @Inject baseFoo;
...
}
Ideally, I'd like to have any instance of Foo to have exactly one
instance of Bar, with the same names. Or, to put it different:
The adminFoo should have an adminBar, and the baseFoo should have a
baseBar.
The only idea that comes to me mind, would be that instances of Foo
can somehow obtain their name ("admin", or null) and use that to
programmatically obtain their bar through the Injector.
Is that possible at all? Any other suggestions?
Thanks,
Jochen
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"google-guice" 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.
For more options, visit https://groups.google.com/d/optout.