Re: Binding objects as both interface and implementation

2010-03-26 Thread Russ
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)

Re: Binding objects as both interface and implementation

2010-03-26 Thread Colin Decker
> > 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

Re: Binding objects as both interface and implementation

2010-03-26 Thread Chris Tucker
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

Re: Binding objects as both interface and implementation

2010-03-26 Thread Russ
> 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

Re: Binding objects as both interface and implementation

2010-03-26 Thread Colin Decker
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

Re: Binding objects as both interface and implementation

2010-03-26 Thread Chris Tucker
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.

Re: Binding objects as both interface and implementation

2010-03-26 Thread Willi Schönborn
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

Re: Binding objects as both interface and implementation

2010-03-26 Thread Russ
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

Re: Binding objects as both interface and implementation

2010-03-26 Thread Chris Tucker
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

Binding objects as both interface and implementation

2010-03-26 Thread Russ
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