Rick wrote: > On Fri, Aug 14, 2009 at 8:09 AM, Max Bowsher<[email protected]> wrote: >> To answer your direct question, passing a parameter to a provider >> invocation is explained here: >> http://code.google.com/p/google-guice/wiki/AssistedInject > > (I know I posted this question in a different way in another recent > thread but it make more sense in this one.) > I'm still confused by this. In the example in the docs here for a Provider: > > http://code.google.com/p/google-guice/wiki/ProviderBindings > > How would you have different connection objects injected in that > constructor for the Provider. Sorry if this is totally newb, but I > don't get it. > > The example then shows > > public class BillingModule extends AbstractModule { > @Override > protected void configure() { > bind(TransactionLog.class) > .toProvider(DatabaseTransactionLogProvider.class); > } > > What I want to do is be able to do something like (Just using the > example above for illustration, by classes are different): > > //ClassA has > public void setTransactionLog(@Named("FooBar") TransactionLog > transactionLog) > > //ClassB has > public void setTransactionLog(@Named("Whatever") TransactionLog > transactionLog) > > and be able to somehow have the "FooBar" version have a different > connection than the "Whatever" version? > > In my case I want to load "FooBar" and "Whatever" versions of the > provider with a different String (path to a resource file), but > stumped how to set it up I thought I could do something like:. > > MyProvider myProvider = new MyProvider("file.xml"); > > bind(ResultOfProvider.class).annotatedWith(Names.named("FooBar")).toProvider(myProvider); > > But the above doesn't seem to work. I'm probably missing something > really fundamental here, so thanks in advance.
What you're doing above seems reasonable to me - you'll need to elaborate on "doesn't seem to work" to get help. Max.
signature.asc
Description: OpenPGP digital signature
