gwt - MVP GWT - 注入(inject) EventBus 的问题

标签 gwt dependency-injection mvp

奇怪的问题,当我注入(inject) EventBus e 时出现异常。该项目是gwt,使用mvp

这是示例代码。

Gin

public interface AppGinjector extends Ginjector
{
  EventBus getEventBus();
  PlaceManager getPlaceManager();
}

这里是入口点

public class MvpEntryPoint implements EntryPoint
{
AppGinjector ginjector = GWT.create(AppGinjector.class);

public void onModuleLoad()
{

  EventBus eventBus = ginjector.geEventBus();
  HelloWorldPanel display = new HelloWorldPanel();
  HelloWorldPresenter presenter = new HelloWorldPresenter( display, eventBus );

  presenter.bind();

  RootPanel.get().add( presenter.getDisplay().asWidget() );

  PlaceManager placeManager =  ginjector.getPlaceManager();
  placeManager.fireCurrentPlace();

}

我使用 gin 1.0 ,gwt-presenter

大家有什么想法吗?

谢谢

编辑:

异常(exception)是

ERROR: Deferred binding result type 'net.customware.gwt.presenter.client.EventBus' should not be abstract. 
ERROR: Unable to load module entry point class com.gmgsys.mvpEntryPoint.client.MvpEntryPoint (see associated exception for details). java.lang.RuntimeException: Deferred binding failed for 'net.customware.gwt.presenter.client.EventBus' (did you forget to inherit a required module?)
...........................

还有 gwt.xml

  <!-- Specify the app entry point class.                   -->
    <entry-point class='com.gmgsys.mvpEntryPoint.client.MvpEntryPoint'/>
    <inherits name='net.customware.gwt.presenter.Presenter' />
    <inherits name="com.google.gwt.inject.Inject" />

最佳答案

我认为您缺少 AbstractPresenterModule 类,该类确保 EventBus 绑定(bind)到 SimpleEventBus:

bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);

应该是这样的:

public class MyClientModule extends AbstractPresenterModule {
  protected void configure() {
     bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
     // more bindings here
  }
}

并且你必须注释你的 Ginjector

@GinModules({ MyClientModule .class })
public interface AppGinjector extends Ginjector
{
  EventBus getEventBus();
  PlaceManager getPlaceManager();
}

关于gwt - MVP GWT - 注入(inject) EventBus 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6563025/

相关文章:

javascript - GWT 阻止来源为 "http://localhost"的框架访问跨来源框架

gwt - 降低GWT的代码复杂度

database - 存储库对数据库有隐藏的依赖性吗?

c# - 如何为使用包装器的 Azure Functions 编写单元测试?

winforms - MSDN 上已退休的内容模型 View 演示者

GWT 2.7 日志记录不工作

css - 我的 CSS 被 Bootstrap CSS 覆盖了

java - Dagger 2 与注入(inject)器类

android - Android中使用Conductor框架时如何保留Mosby的Presenter?

asp.net - 我可以说 MVP = 3 Tier Archi 吗?