我已经按照this tutorial的建议实施了GWT应用程序。我还下载了示例代码,并且我注意到演示的每个演示者都需要注入主演示器构造函数中以进行实例化。笔者在源包含在此:GWT /杜松子酒Presenter实例化
public class GreetingPresenter extends WidgetPresenter<GreetingPresenter.Display> {
// FUDGE FACTOR! Although this is not used, having GIN pass the object
// to this class will force its instantiation and therefore will make the
// response presenter listen for events (via bind()). This is not a very good way to
// achieve this, but I wanted to put something together quickly - sorry!
private final GreetingResponsePresenter greetingResponsePresenter;
@Inject
public GreetingPresenter(final Display display, final EventBus eventBus, final DispatchAsync dispatcher, final GreetingResponsePresenter greetingResponsePresenter) {
super(display, eventBus);
this.dispatcher = dispatcher;
this.greetingResponsePresenter = greetingResponsePresenter;
bind();
}
我核实,如有主持人没有得到GreetingPresenter注射,也不会被实例化。出于演示的目的,这很酷,因为整个应用程序只有两个演示者,但在真实世界的应用程序中,这可能是一个严重的不便。
完成Presenter实例化的正确方法是什么?
编辑:包括参考GIN相关类:
演示模块:
public class GreetingClientModule extends AbstractPresenterModule {
@Override
protected void configure() {
bind(EventBus.class).to(DefaultEventBus.class).in(Singleton.class);
bind(PlaceManager.class).in(Singleton.class);
bindPresenter(GreetingPresenter.class, GreetingPresenter.Display.class, GreetingView.class);
bindPresenter(GreetingResponsePresenter.class, GreetingResponsePresenter.Display.class, GreetingResponseView.class);
bind(AppPresenter.class).in(Singleton.class);
bind(CachingDispatchAsync.class);
}
}
Ginjector:
@GinModules({ ClientDispatchModule.class, GreetingClientModule.class })
public interface GreetingGinjector extends Ginjector {
AppPresenter getAppPresenter();
PlaceManager getPlaceManager();
}
我下载了源代码并进行了测试,它包含了您提到的类。然而,GreetingResponsePresenter工作需要“FUDGE FACTOR”:S – 2012-04-12 21:10:56