문제

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?

도움이 되었습니까?

해결책

You don't need the explicit binding, and in fact I think it will override the @Provides method. I don't know of a nice way to use asEagerSingleton() with a @Provides method, instead consider a Provider<T> implementation.

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

Looking at the actual stuff you are generating/wiring, I find it useful to actually @Inject the ActivityManager instance to the parent of the SimplePanel (or whatever you are using as the display), and calling setDisplay there instead. At least to me, this makes it easier to replace the display or change it, as it is part of that block of code instead of part of the module. It also removes the need to create an eager singleton.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top