OK... getting closer to this.
My issue now is that most of my objects are requiring custom initialization.
For example, with cassandra I have to read the config in, create a cluster builder, set the options for the connection, then build a new session and cluster object.
I could use @Provides methods I think.. BUT then I don't get service start and stop. Because I'd need a way to stop them.
What I was thinking of doing, was having a harness like a service manager to start all my services.
Then I would have this return a new binding... which I can use to create a new Injector which can inject all my newly created objects.
I just can't figure that part out yet.
what I need is the ability to bind a class to an already instantiated object.. since I've just instantiated it.
Maybe one way to do it is to make each Service a Module and @Provides a member...
Or make my own custom binding that has a bunch of @Provides and then I can just have it return the newly created object. And I would then just use a bunch of bindings..
Actually.. I think that would work fine.
So every object I want to inject could be done by adding a new binding like?
class ProvideByObject<T> extends AbstractModule {
private T value;
ProvideByObject(T value) {
this.value = value;
}
@Override
protected void configure() {
}
@Provides
T getValue() {
return value;
}
}