afterburner.fx
afterburner.fx copied to clipboard
Injection context ignored for presenter members at first
I am trying to instantiate a view
Criterium newValue = ...;
ValueView valueView = new ValueView (s ->
{
if ("criterium".equals (s))
{
return newValue;
}
return null;
});
with provided injection context. ValuePresenter
has a member Criterium criterium
wgich should be injected the instance supplied by the context. But instead I get an exception, because Criterium
has no no-args-constructor. Instead of using the injection context
public static <T> T instantiatePresenter(Class<T> clazz, Function<String, Object> injectionContext) {
Object presenter = registerExistingAndInject(instanceSupplier.apply(clazz));
...
tries an injection of the presenter and subsequently an injection of members. All without usage of the context.
Later instantiatePresenter(Class<T>, Function<String, Object>)
loops over the members again and then (but too late) uses the injection context.
I can work around by using setters on the presenter, or supplying a no-args-constructor for Criterium
, that way criterium would be replaced by the supplied instance later (but that feels wrong).
Is it working as intended?
I have the same problem. It works for primitive types or strings (because of https://github.com/AdamBien/afterburner.fx/blob/master/src/main/java/com/airhacks/afterburner/injection/Injector.java#L145) but not for custom/complex objects.
I am havin the same issue in my project.
I have proposed fix #85 for this that prioritizes the injection context over default instantiation. For the detail see issue #65.