Hi Nik,
let me first say that it is the idea of the container to not mix up dependency management code with application code.
Instead state from command line arguments or such is passed to the bootstrapping process.
It can than be bound for particular constructor parameters using different methods.
One would be to use presets.
class Example1Module1 extends BinderModuleWith<Properties> {
@Override
protected void declare(Properties properties) {
bind(MyClass.class).toConstructor(
BoundParameter.constant(String.class, properties.getProperty("x")),
BoundParameter.constant(Integer.class, (Integer)properties.get("y")));
}
}
Properties props = new Properties();
props.put("x", "abc");
props.put("y", 12);
Presets presets = Presets.EMPTY.preset(Properties.class, props);
Globals globals = Globals.STANDARD.presets(presets);
Injector injector = Bootstrap.injector(Example1Module1.class, globals);
Instead of using the Properties as a general data map you could also have a special class holding the two values you want to bind.
Another way could be to use named instances:
class Example1Module2 extends BinderModule {
@Override
protected void declare() {
bind(MyClass.class).toConstructor(
instance(named("foo"), raw(String.class)),
instance(named("bar"), raw(int.class))
);
// the below may of course appear in any other module
bind(named("foo"), String.class).to("abc");
bind(named("bar"), int.class).to(12);
}
}
Injector injector = Bootstrap.injector(Example1Module2.class);
Remember that you can easily point out that type or instance you want to have injected for particular constructor arguments.
Using BoundParameter you could provide a Supplier that dynamically provides the values you want.
Note that you do not have to specify all constructor arguments. These are just hints you could give to the container when you want something particular to be injected.
Let me know if that was helpful or otherwise describe in more detail what it is you want and maybe even why.
Best regards
Jan