私はプロジェクトで Guice を使用しており、デフォルトの注入されたプロバイダーがどのように機能するかを理解しようとしています。マニュアルの「Injecting Providers」セクション ( https://github.com/google/guice/wiki/InjectingProviders ) には、次の簡単な例があります。
public class RealBillingService implements BillingService {
private final Provider<CreditCardProcessor> processorProvider;
private final Provider<TransactionLog> transactionLogProvider;
@Inject
public RealBillingService(Provider<CreditCardProcessor> processorProvider,
Provider<TransactionLog> transactionLogProvider) {
this.processorProvider = processorProvider;
this.transactionLogProvider = transactionLogProvider;
}
public Receipt chargeOrder(PizzaOrder order, CreditCard creditCard) {
CreditCardProcessor processor = processorProvider.get();
TransactionLog transactionLog = transactionLogProvider.get();
/* use the processor and transaction log here */
}
}
さて、私が知りたいのは、processorProvider.get() と transactionLogProvider.get() のデフォルトの実装が正確に何をするかです。
例えば:
- 常にCreditCardProcessor/TransactionLog の新しいインスタンスを作成する
- オブジェクトのプールを使用する
- 何か他の..
現在、プロジェクトで奇妙な動作が発生しているため、これを尋ねています。これは、デフォルトのプロバイダーが何らかのキャッシュ戦略を使用している場合に説明される可能性があります..
ありがとう