Yeah, that works:
bind(FooComponentImpl.class)
.annotatedWith(Names.named(ONE))
.to(FooComponentImpl.class)
.in(Scopes.SINGLETON);
bind(FooComponentImpl.class)
.annotatedWith(Names.named(TWO))
.to(FooComponentImpl.class)
.in(Scopes.SINGLETON);
bind(FooComponent.class)
>
> Don't you mean
>
>
> bind(FooComponent.class).annotatedWith(named("1")).to(FooComponentImpl.class).in(Scopes.SINGLETON);
>
> Else how does Guice resolve requests for FooComponent?
You need that too, though I think it actually needs to be:
bind(FooComponent.class).annotatedWith(named("1")).t
On Fri, Mar 26, 2010 at 7:07 PM, Russ wrote:
> >
> bind(FooComponentImpl.class).annotatedWith(named("1")).in(Scopes.SINGLETON);
> >
> > will fail (no implementation for FooComponentImpl annotated with
> > @Named(value=1) was bound).
>
> Yes, exactly what I see in my test.
>
> > So you need to wri
> bind(FooComponentImpl.class).annotatedWith(named("1")).in(Scopes.SINGLETON);
>
> will fail (no implementation for FooComponentImpl annotated with
> @Named(value=1) was bound).
Yes, exactly what I see in my test.
> So you need to write
>
> bind(FooComponentImpl.class).annotatedWith(named("1")).t
The behavior here seems very strange.
bind(FooComponentImpl.class).annotatedWith(named("1")).in(Scopes.SINGLETON);
will fail (no implementation for FooComponentImpl annotated with
@Named(value=1) was bound).
So you need to write
bind(FooComponentImpl.class).annotatedWith(named("1")).to(FooCom
My expectation would be no (though on preview it looks like Willi might
disagree, so a test seems in order!). I think what you actually want is:
bind(FooCompmentImpl.class).annotatedWith(Names.named("1")).in(Scopes.SINGLETON);
bind(FooCompmentImpl.class).annotatedWith(Names.named("2")).in(Scopes.
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
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
Looks like you want something like this:
bind(FooComponent.class).to(FooComponentImpl.class);
bind(FooCompmentImpl.class).in(Scopes.SINGLETON);
See:
http://code.google.com/docreader/#p=google-guice&s=google-guice&t=Scopes.
Specifically:
==
In linked bindings, scopes apply to the binding so
Consider the following:
I create the following interface:
interface FooComponent {
}
that I make my own extension of a third party library's class
implement:
class FooComponentImpl extends ThirdPartyFooComponent
implements FooComponent {
}
I add "shadow" methods to FooComponent to allow me
10 matches
Mail list logo