2

我正在尝试配置我的 GIN 模块以将ActivityManager请求绑定到DefaultActivityManagerProvider

import com.google.inject.Provider;

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

但是当我去实际绑定它时:

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

bind(...)我在语句中收到编译错误:

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>>

我在这里做错了什么?!?我已经遵循了无数的例子,比如这个,但不知道为什么我会收到错误!提前致谢!

4

1 回答 1

3

未正确支持 toProvider

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

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

提供者需要是公共静态的

static class DefaultActivityManagerProvider implements Provider<ActivityManager> {
    @Override
    public ActivityManager get() {
        return new ActivityManager(new MyDefaultActivityMapper());
    }
}
于 2012-11-28T21:44:10.107 回答