2

I am trying to configure my GIN module to bind ActivityManager requests to a DefaultActivityManagerProvider:

import com.google.inject.Provider;

public class DefaultActivityManagerProvider implements Provider<ActivityManager> {
    @Override
    public ActivityManager get() {
        return new ActivityManager(new MyDefaultActivityMapper());
    }
}

But when I go to actually bind it:

public class MyAppGinModule extends AbstractGinModule {
    @Override
    protected void configure() {
        bind(ActivityManager.class).toProvider(DefaultActivityManagerProvider.class);
    }
}

I get a compile error on the bind(...) statement:

Bound mismatch: The generic method toProvider(Class<I>) of type
GinLinkedBindingBuilder<T> is not applicable for the arguments
(Class<DefaultActivityManagerProvider>). The inferred type
DefaultActivityManagerProvider is not a valid substitute for the
bounded parameter <I extends Provider<? extends ActivityManager>>

What am I doing wrong here?!? I have followed countless examples such as this one and can't figure out why I am getting the error! Thanks in advance!

Community
  • 1
  • 1
  • And what version of Guice and GWT? You have googled that error message, haven't you? – Alan Stokes Nov 17 '12 at 22:57
  • GWT - 2.4, GIN - 2.0, Guice - 3.0 and yes to googling/preliminary research (with zero results) :-( –  Nov 17 '12 at 22:59
  • " for the bounded parameter >" Think you might be missing part of the error message there - it should specify what type it is expecting the bounds to fit with. (EDIT: I bet "The generic method toProvider(Class)" also ought to have some generics as well) – Colin Alworth Nov 18 '12 at 05:08
  • Good catch @Colin - I think StackOverflow was parsing out some of the generic stuff because I added the compile error as a block quote (with a leading "> " instead of a code block (with a leading quadruple indentation " "). I updated the compile error and verified it matches what Eclipse is showing me. Thanks again! –  Nov 18 '12 at 11:00
  • Not sure if this matters, but the `Provider` I'm using is a `com.google.inject.Provider`. I did a type search for anything called "Provider" on my classpath, and saw that there is one inside the `javax.inject.jar` at `javax.inject.Provider`. **Am I using the wrong `Provider`?** –  Nov 18 '12 at 11:15
  • com.google.inject.Provider extends javax.inject.Provider, so that shouldn't cause a problem; normally you'd stick with the former in Gin/Guice code. Although other people seem to have had a similar problem with [GWT 2.2 / Gin 1.5](https://groups.google.com/group/google-gin/tree/browse_frm/month/2011-03/ab1683e8f0f131f3?rnum=1&lnk=ol&pli=1). – Alan Stokes Nov 18 '12 at 16:19
  • Is it the same ActivityManager class in each place? – Alan Stokes Nov 18 '12 at 16:23
  • No, there will be other ActivityManagers. If you're thinking about scope (prototype vs. singleton) I'm not worried about that right at this moment, I just want to get this thing working first! –  Nov 18 '12 at 17:47
  • Giving up on GIN, switching to [DIY-DI](http://misko.hevery.com/2010/05/26/do-it-yourself-dependency-injection/). –  Nov 18 '12 at 20:23
  • 1
    The comment about 'the same ActivityManager' was trying to make sure you weren't binding `com.a.ActivityManager`, but asking for injection of `org.b.ActivityManager` - since they don't match, Guice (actually, Java) thinks you are talking crazy. Since the only `import` you list is for `Provider`, we can't tell if this was done right. – Colin Alworth Nov 19 '12 at 06:00

1 Answers1

3

toProvider is not properly supported

http://code.google.com/p/google-gin/wiki/GinFaq

http://code.google.com/p/google-gin/wiki/GuiceCompatibility

The provider need to be public static

static class DefaultActivityManagerProvider implements Provider<ActivityManager> {
    @Override
    public ActivityManager get() {
        return new ActivityManager(new MyDefaultActivityMapper());
    }
}
Rebzie
  • 310
  • 1
  • 3
  • 9