-
Notifications
You must be signed in to change notification settings - Fork 440
Description
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:
- Why Field Injection is Fading Away with Spring 5.0
- Why Is Field Injection Not Recommended?
- What exactly is Field Injection and how to avoid it?
- (dozens or hundreds more)
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.