レベルエンター山本大のブログ

面白いプログラミング教育を若い人たちに

BLOCKVROCKリファレンス目次はこちら

[翻訳]Guice User's Guide ■34. Appendix: How the Injector resolves injection requests


付録:Injectorはどうやってインジェクションの要求を解決しているか?

The injector's process of resolving an injection request depends on the bindings that have been made and the annotations found on the types involved. Here is a summary of how an injection request is resolved:


Injectorがインジェクション要求を解決するプロセスは、バインディングでひも付けされたクラスの上で見つけられたアノテーションに関係します。



1. Observe the Java type and the optional "binding annotation" of the element to be injected. If the type is com.google.inject.Provider, perform resolution for the type indicated by T instead. Find a binding for this (type, annotation) pair. If none, skip to #4.


1. Javaタイプと、インジェクトされた省略可能な「バインディングアノテーション」の要素を観察します。型がcom.google.inject.Provider()であるなら、代わりにTによって示された型の解決を実行します。バインディングのための「型・アノテーション」のペアを見つけます。なければ、#4までスキップします。


2. Follow transitive bindings. If this binding links to another binding, follow this edge and check again, repeating until we reach a binding which does not link to any other binding. We are now at the most specific explicit binding for this injection request.


2. 推移的なバインディングを追跡します。このバインディングが別のバインディングにリンクされているなら、それをたどって、もう一度チェックします。いかなる他のバインディングにもリンクされていないバインディングに達するまで繰り返します。この時点で、インジェクト要求のための最も特定の明白なバインディングに居ることになります。


3. If this binding specifies an instance or a Provider instance, we're done; use this to fulfill the request.


3. このバインディングインスタンスかProviderインスタンスを指定しているなら完了です。要求を実現させるのにこれを使用します。


4. If, at this point, the injection request used an annotation type or value, we have failed and we produce an error.


4. ここでインジェクト要求がアノテーションタイプまたは値を使用していたら、アプリケーションは中断してエラーを生成します。


5. Otherwise examine the Java type for this binding; if an @ImplementedBy annotation is found, instantiate the referenced type. If a @ProvidedBy annotation is found, instantiate the referenced provider and use it to obtain the desired object. Otherwise attempt to instantiate the type itself.


5. でなければ、このバインディングのためのJavaタイプがないかどうかを調べます。@ImplementedByアノテーションがあれば、参照する型をインスタンス化します。@ProvidedByアノテーションがあれば、参照するプロバイダーをインスタンス化します。そして、必要なオブジェクトを入手するために使用します。でなければ、タイプ自体のインスタンス化を試みます。