I want to make a binding using a method annotated with @Provides
into an eager singleton. I\'ve found bug 216, which suggests this isn\'t possible, but doesn\'t men
Why not to use
bind(Logic.class).toInstance(LogicCreator.create(dep));
//ohh we missing dep
then we can do this
class LogicProvider implements Provider {
private final SomeDep dep;
@Inject
public LogicProvider(SomeDep dep) {
this.dep = dep;
}
@Override
public Logic get() {
return LogicCreator.create(dep);
}
}
and then
bind(Logic.class).toProvider(LogicProvider.class).asEagerSingleton();
You can even pass SomeDep dep
to your provider as Provider
and then call providerDep.get()
in LogicCreator.create()
that would be a bit more robust.