InjectingProviders · google/guice Wiki
With normal dependency injection, each type gets exactly one instance of each of its dependent types. The RealBillingService gets one CreditCardProcessor and one TransactionLog. Sometimes you want more than one instance of your dependent types. When this flexibility is necessary, Guice binds a provider. Providers produce a value when the get() method is invoked:
public interface Provider<T> { T get(); }The provider's type is parameterized to differentiate a Provider<TransactionLog> from a Provider<CreditCardProcessor>. Wherever you inject a value you can inject a provider for that value.
Read full article from InjectingProviders · google/guice Wiki
No comments:
Post a Comment