Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injection context ignored for presenter members at first #71

Open
mfuerstenau opened this issue Dec 2, 2016 · 3 comments
Open

Injection context ignored for presenter members at first #71

mfuerstenau opened this issue Dec 2, 2016 · 3 comments

Comments

@mfuerstenau
Copy link

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?

@tobiasdiez
Copy link

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.

@adrianopolus
Copy link

I am havin the same issue in my project.

@paulhudsonx
Copy link

I have proposed fix #85 for this that prioritizes the injection context over default instantiation. For the detail see issue #65.

dlemmermann added a commit to dlsc-software-consulting-gmbh/afterburner.fx that referenced this issue Aug 20, 2020
…ien#78: Use injection context already on inital presenter initialization AdamBien#80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants