GWT-GINチュートリアルページの基本的なセットアップ手順に従いました。ステップ3(バインディングの宣言)を実行していて、GINのBinderAPIの使用方法を理解しようとしています。
public class MyModule extends AbstractGinModule {
@Override
public void configure() {
// 1. Declare an instance of EventBus and make sure every
// injection request pulls back the same instance.
EventBus eventBus = new EventBus();
bind(EventBus.class).to??? // no toInstance() method!
// 2. Declare two instances of Fizz using different constructors,
// and allow the injection of either of them.
Fizz f1 = new Fizz(true, "oh yeah", null);
Fizz f2 = new Fizz();
bind(Fizz.class).to??? // no toInstance() AND don't know how to choose f1 or f2!
// 3. Declare a List of Buzz objects and allow them to be
// injectable.
List<Buzz> buzzes = new ArrayList<Buzz>();
configureBuzzes(buzzes); // adds configured Buzz objects to the list
bind(???).to(buzzes); // no toInstance() methods AND how to bind List<?>.class?!
// 4. Conditionally bind SomePlace to Place *only* when we want the default Place
// that 'historyHandler.handleCurrentHistory()' will go to when called onModuleLoad.
bind(Place.class).to(SomePlace.class); // forces me to only have SomePlace instances!
}
}
上記の4つのユースケースは、私が苦労しているものです。それぞれ:
EventBus
クライアントが要求するたびに同じインスタンスを再利用するにはどうすればよいですか?- 上記の#1から構築して、さまざまなシナリオで注入できる2つ以上のさまざまなインスタンスを作成するにはどうすればよいですか?
List
何かを注入する方法は?- 上記の#2と同じかもしれませんが、2 + Placeサブクラスをバインドする方法は
Place.class
?
前もって感謝します!