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 mention the @Provides
annotation explicitly.
I currently have a class that requests the eager
singletons in time by itself being a singleton, but it's not a very nice solution.
public class LogicModule extends AbstractModule {
@Override public void configure() {
bind(SomeDep.class);
bind(MyWorkaround.class).asEagerSingleton();
}
// cannot add eager requirement here
@Provides @Singleton Logic createLogic(SomeDep dep) {
return LogicCreator.create(dep);
}
private static class MyWorkaround {
@Inject Logic logic;
}
}
Can I change something near the comment that would make the workaround class obsolete?