Config property annotation approach #11
Replies: 6 comments 14 replies
-
IMO a single annotation is better. With a single annotation all options are grouped together so that the developer does not have to remember the name of other combineable annotations. He can simply use the autocompletition of most IDEs. I also would like to see useage like so 1. a. |
Beta Was this translation helpful? Give feedback.
-
Here's a sampling of other config system annotations that seem to overlap with this discussion. These both assume that the configuration is two-way, it can be read from multiple 1..n sources, and written / created / populated if it the config file doesn't exist, and also documentation and help systems can be generated from this information. I'm intentionally not mentioning the exact project that uses these systems as I don't want to create a bias ("for" or "against") the concepts based on where/who they are used. Example from config system that's been in use since 2005 /**
* @since <since-text>
* @deprecated <deprecated-text>
*/
@Parameter( name = "parameter",
alias = "myAlias",
property = "a.property",
defaultValue = "an expression, possibly with ${variables}",
readonly = <false|true>,
required = <false|true> ) Example from config system that's been in use since 2011 @Config( moduleId=<String>, // name of configuration source file
name=<String>, // name of property in config
type=<Type>, // used to indicate conversion/validation type - eg: String in properties file to validated timestamp that is in the past
category=<String> ) // for grouping similar config items together when writing config
@Comment(<String[]>) // comment seen in written config
@Name(<String>) // name seen in config - alt usage for @Config(name="") - used mainly for config that crosses modules/groups (eg: work.dir)
@RangeInt(min=<int>, max=<int>) // validate valid int range
@RangeDouble(min=<double>, max=<double>) // validate valid double range
@LangKey(<String>) // expose lang/translate key for description
@RequiresRestart // used to indicate that a restart of the
// component is needed if config changes at runtime.
@Ignore // used to skip entry when processing config I don't want to see Jakarta Config 1.0 have these concepts, lets get the minimal viable solution out first. We can discuss these "nice to have" features for version 2.0 |
Beta Was this translation helpful? Give feedback.
-
I like the idea of a single annotation too. It defines a scope and all possible options within that scope. It means that in your IDE you press a button to get all possible combination of parameters to choose from. IMO, it's more user friendly then using different annotations, assuming that some of them may come from different third-party packages. |
Beta Was this translation helpful? Give feedback.
-
I prefer the annotation |
Beta Was this translation helpful? Give feedback.
-
Scenarios to consider for defaults:
@Inject
@ConfigProperty(name = "foo", defaultValue = "foo")
String foo;
ConfigProvider.getConfig().getValue("foo", String.class); 1.1 If yes how about when you get two injection points to the same key name? @Inject
@ConfigProperty(name = "foo", defaultValue = "foo")
String foo;
@Inject
@ConfigProperty(name = "foo", defaultValue = "anotherFoo")
String anotherFoo;
ConfigProvider.getConfig().getValue("foo", String.class); 1.2 Same issue for expansion: @Inject
@ConfigProperty(name = "foo", defaultValue = "foo")
String foo;
@Inject
@ConfigProperty(name = "foo", defaultValue = "anotherFoo")
String anotherFoo;
@Inject
@ConfigProperty(name = "bar", defaultValue = "${foo}")
String bar; If we consider that the default is local to the injection point only, the rules are clear and remove a lot of the ambiguity. On the other hand, what I have observed is that users expect the default to be generally available when set at the injection point. Maybe one reason is how we perceive the meaning of a If the I also have some thoughts about complex objects but before going there we should probably discuss and decide the simple cases first and then adjust if possible. |
Beta Was this translation helpful? Give feedback.
-
I noticed there is a |
Beta Was this translation helpful? Give feedback.
-
Discussion about annotation.
Should we use a single annotation?
@ConfigProperty(value = "...", defaultValue = ".."
Should we use more:
Beta Was this translation helpful? Give feedback.
All reactions