Skip to content

Support method injection with @ParentCommand (and others). #2444

@garretwilson

Description

@garretwilson

The general consensus in the dependency injection community over the past couple of decades has been to move away from field injection, to prefer constructor injection, and to use method injection as a last resort. Having classes that allow other tools to come and muck around with their fields is no longer best practice. A quick search yielded the following:

In general picocli supports this: e.g. I can annotate a setMyOption(…) method with @Option, or setSpec(…) with @Spec. But for some reason @ParentCommand (and probably a few others; I didn't do a comprehensive search, as this was the one I ran into) only supports field injection.

Was this an oversight?

All annotations that support field injection need to support method injection as well; even if the library doesn't promote this practice, it should at least support it. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions