我正在尝试配置我的 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>>
我在这里做错了什么?!?我已经遵循了无数这样的例子,但无法弄清楚为什么我会收到错误!提前感谢!
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());
}
}