On 26/03/2010 19:11, Russ wrote:
Thanks for the quick response Chris.
What if ViewImpl needed multiple references to different
FooComponentImpl objects? Do I annotate them to differentiate them?
class ViewImpl extends ThirdPartyContainer
implements View {
@Inject @Named("1") private FooComponentImpl _comp1;
@Inject @Named("2") private FooComponentImpl _comp2;
@Inject @Named("3") private FooComponentImpl _comp3;
void init() {
// add() is a ThirdPartyFooComponent API method written
// in terms of ThirdPartyFooComponent
add(_comp1);
add(_comp2);
add(_comp3);
}
}
bind(FooComponent.class).to(FooComponentImpl.class);
bind(FooCompmentImpl.class).annotatedWith(Names.named("1")).in(Scopes.SINGLETON);
bind(FooCompmentImpl.class).annotatedWith(Names.named("2")).in(Scopes.SINGLETON);
bind(FooCompmentImpl.class).annotatedWith(Names.named("3")).in(Scopes.SINGLETON);
Will ModelImpl get the right references?
Looks correct for me.
class ModelImpl implements Model {
@Inject @Named("1") private FooComponent _comp1;
@Inject @Named("2") private FooComponent _comp2;
@Inject @Named("3") private FooComponent _comp3;
}
--
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.