2

Here is my Gin module:

public class FooGinModule extends AbstractGinModule {

  @Override
  protected void configure() {
    ...

    bind(ActivityManager.class).asEagerSingleton();

    ...
  }

  @Provides
  @Singleton
  public ActivityManager getActivityManager(EventBus eventBus, SimplePanel display,
      ActivityMapper activityMapper) {
    final ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
    activityManager.setDisplay(display);
    return activityManager;
  }

}

When I try to gwt-compile, I get the following error:

[ERROR] No @Inject or default constructor found for class com.google.gwt.activity.shared.ActivityManager

Am I specifying the @Provides method wrong?

4

1 回答 1

3

您不需要显式绑定,实际上我认为它会覆盖该@Provides方法。我不知道使用方法的好asEagerSingleton()方法@Provides,而是考虑Provider<T>实现。

bind(ActivityManager.class)
    .toProvider(MyActivityManagerProvider.class)
    .asEagerSingleton();

查看您正在生成/连接的实际内容,我发现@InjectActivityManager实例实际应用于父级SimplePanel(或您用作显示的任何内容)并在那里调用是很有用的setDisplay。至少对我来说,这使得更换或更改显示器变得更容易,因为它是该代码块的一部分,而不是模块的一部分。它还消除了创建渴望单例的需要。

于 2012-02-19T23:48:08.977 回答