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

Dependency injection from inherited class doesn't work if class itself doesn't have one #338

Open
brian-mulier-p opened this issue Sep 27, 2023 · 1 comment

Comments

@brian-mulier-p
Copy link

Expected Behavior

Dependency injection for parent class should work even if I don't provide a DI on the end class

Actual Behaviour

See this boilerplate

public class InjectCommand implements Runnable {
    @Inject
    private ApplicationContext applicationContext;

    public void run() {
        System.out.println("App Context: " + applicationContext);
    }
}

with

@Command(name = "picocli-working", description = "...",
    mixinStandardHelpOptions = true)
public class WorkingCommand extends InjectCommand {
    @Inject
    @Nullable
    private ObjectMapper mapper;

    public static void main(String[] args) throws Exception {
        PicocliRunner.run(WorkingCommand.class, args);
    }
}

the dependency injection is properly propagated to the parent class and it works
image

With that (notice I removed the dependency injection from the end class) it won't work and I get a null injection

@Command(name = "picocli-not-working", description = "...",
    mixinStandardHelpOptions = true)
public class NotWorkingCommand extends InjectCommand {
    public static void main(String[] args) throws Exception {
        PicocliRunner.run(NotWorkingCommand.class, args);
    }
}

image

Also, if any fix, would it be possible to backport it on 3.X.X ? Thanks !

Steps To Reproduce

No response

Environment Information

No response

Example Application

https://github.com/brian-mulier-p/micronaut-picocli-di-issue

Version

PICO CLI: 5.0.1, Micronaut: 4.0.3

@sdelamo
Copy link
Contributor

sdelamo commented Oct 24, 2023

any idea why this is happening @dstepanov ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

No branches or pull requests

3 participants