我已經按照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