Using an @Provides method rather than writing a Provider implementation would make that even easier.
-- Colin On Thu, Feb 23, 2012 at 2:44 PM, Noctarius <[email protected]>wrote: > Hi Warren, > > what I mean is something like the following (just written down, > could be made nice by using constants etc). > > interface Foo { > > } > > class FooImplStandard implements Foo { > > } > > class FooImplSpecial implements Foo { > > } > > class FooProvider implements Provider<Foo> { > > @Inject @Named("Foo") > > private String implementation; > > @Inject > > private Injector injector; > > > > public Foo get() { > > if ("Standard".equals(implementation)) > > return injector.getInstance(FooImplStandard.class); > > else > > return injector.getInstance(FooImplSpecial.class); > > } > > } > > class FirstModule extends AbstractModule { > > public void configure() { > > bindConstant().annotatedWith(Names.named("Foo")).to("Standard"); > > } > > } > > class SecondModule extends AbstractModule { > > public void configure() { > > bind(Foo.class).toProvider(FooProvider.clas).in(Singleton.class); > > } > > } > > > Am 23.02.2012 20:36, schrieb Warren Bell: > > Can you elaborate a little ? > > > > Thanks, > > > > Warren Bell > > > > On 2/23/12 10:03 AM, Noctarius wrote: > >> Why not use a Provider implementation with the injected depedency? > >> > >> Am 23.02.2012 18:30, schrieb Warren: > >>> I have 2 modules, module1 and module2. I bind a type1 in module1 and I > >>> then need to inject type1 into module2. I have tried the > >>> createChildInjector, but have run into problems doing it that way. > >>> What is the best way to do this? > >>> > >>> Thanks > >>> > >>> Warren Bell > >>> > > -- > 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. > > -- 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.
