Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top