Locked History Actions

Diff for "guice/Manual/UserGuide/Bindings"

Differences between revisions 1 and 2
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Overview of bindings in Guice
Bindings
インジェクタの仕事は、オブジェクトのグラフを構築するこおである。
あなたが、型を指定してそのインスタンスを要求すると、インジェクタはビルドすべきものを調べ、依存性解決をし、すべてをワイアリングする。
インジェクタにバインディング指定することにより、依存性解決の方法を指示する。
Line 6: Line 7:
The injector's job is to assemble graphs of objects. You request an instance of a given type, and it figures out what to build, resolves dependencies, and wires everything together. To specify how dependencies are resolved, configure your injector with bindings.
Creating Bindings
== バインディングの作成 ==
Line 9: Line 9:
To create bindings, extend AbstractModule and override its configure method. In the method body, call bind() to specify each binding. These methods are type checked so the compiler can report errors if you use the wrong types. Once you've created your modules, pass them as arguments to Guice.createInjector() to build an injector. バインディングを作成するには、AbstractModuleを拡張しそのconfigureメソッドをオーバライドすればよい。
メソッドボディにてbind()を使い、各バインディングを指定する。
これらのメソッドはタイプチェックされているので、型が誤っているときはエラーが報告される。
モジュールを作成したら、Guice.createInjector()の引数として渡せばよい。
Line 22: Line 25:
More Bindings
== さらなるバインディング ==

バインディング

インジェクタの仕事は、オブジェクトのグラフを構築するこおである。 あなたが、型を指定してそのインスタンスを要求すると、インジェクタはビルドすべきものを調べ、依存性解決をし、すべてをワイアリングする。 インジェクタにバインディング指定することにより、依存性解決の方法を指示する。

バインディングの作成

バインディングを作成するには、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.