我已按照GWT-GIN 教程页面上的基本设置说明进行操作。我在第 3 步(声明绑定)并试图弄清楚如何使用 GIN 的 Binder API。
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!
}
}
上面的四个用例是我正在努力解决的问题。分别:
EventBus
每次客户端请求时如何重用相同的实例?- 从上面的#1 构建,如何在不同的场景下注入 2+ 个不同的实例?
- 如何注入
List
任何东西? - 可能与上面的 #2 相同,但是如何将 2+ Place 子类绑定到
Place.class
?
提前致谢!