バインディング
インジェクタの仕事は、オブジェクトのグラフを構築するこおである。 あなたが、型を指定してそのインスタンスを要求すると、インジェクタはビルドすべきものを調べ、依存性解決をし、すべてをワイアリングする。 インジェクタにバインディング指定することにより、依存性解決の方法を指示する。
バインディングの作成
バインディングを作成するには、AbstractModuleを拡張しそのconfigureメソッドをオーバライドすればよい。 メソッドボディにてbind()を使い、各バインディングを指定する。 これらのメソッドはタイプチェックされているので、型が誤っているときはエラーが報告される。 モジュールを作成したら、Guice.createInjector()の引数として渡せばよい。
Use modules to create linked bindings , instance bindings , @Provides methods , provider bindings
- and
untargetted bindings .
さらなるバインディング
In addition to the bindings you specify the injector includes built-in bindings . When a dependency is requested but not found it attempts to create a just-in-time binding . The injector also includes bindings for the providers of its other bindings.