I'm new to Guice, so excuse me if this is a dumb question, but I'm finding it quite frustrating.
In my module I construct an object which is a member of a framework that I do not control. I then bind that instance so that I can access it later with injector.getInstance(FrameworkClass.class);
When I construct that object, I want to use one of my own objects which itself is annotated to be injected by constructor.
i.e.
public class MyClass {
OtherClass dependency;
@Inject
Public MyClass(OtherClass dependency) {
....
}
}
public class AModule extends AbstractModule {
protected void configure() {
MyClass frameworkDependency = ???
FrameworkClass fc = new FrameworkClass(frameworkDependency);
bind(FrameworkClass.class).toInstance(fc);
}
}
In this example OtherClass is just a simple class with no annotations but a default empty constructor, so Guice should just new one up and provide it to MyClass constructor as far as I understand.
My question is How do I get access to a new instance of MyClass in my module so that I can provide it to the framework class?
Previously I had my own class injected via Field Injection, so it looked like this:
public class MyClass {
@Inject
OtherClass dependency;
}
public class AModule extends AbstractModule {
protected void configure() {
MyClass frameworkDependency = new MyClass();
requestInjection(frameworkDependency);
FrameworkClass fc = new FrameworkClass(frameworkDependency);
bind(FrameworkClass.class).toInstance(fc);
}
}
I would prefer to keep MyClass as constructor injected if possible.