Hi,
What if the provider throws an exception?
Let say, for example, the "new DatabaseTransactionLog()" throws a
DatabaseException (or anything), how should this be handled?
For more information:
http://code.google.com/p/google-guice/wiki/ProvidesMethods
Is there some way to override the scope of the Provider specified by a
@Provides method either in #configure() or in a derived class?
For instance, let's say you define a @Provides method with default scope,
but then want to make another version of the Module which applies
@Singleton scope to this method. How might you specify this override?
How do you use this (below) on the @Inject side? What do you annotate as
`@Named("PayPal API key")`?
{{{
@Provides @PayPal
CreditCardProcessor providePayPalCreditCardProcessor(
@Named("PayPal API key") String apiKey) {
...
Who should be the responsable of release a resource provided by a
Provider/Provider Method?, i. e. a Connection. The module? The aplication?
Here is how I've used it;
I had to have providers for IFoo which needed to return different impl old
vs new,
in my module, I added providers like
@Provides @Named("old")
IFoo getFoo() {
.
}
and
@Provides @Named("new")
IFoo getFoo() {
.
}
On injector site, couple of ways to get desired IFoo
* Using constructor
@Inject
MyObj(@Named("old") IFoo foo) {
this.foo = foo;
}
* or explicitly using injector to get desired instance
IFoo foo = injector.getInstance(Key.get(IFoo.class, Names.named("old")));
injector is of course injected in calling class :)
Hope this helps.