-
Notifications
You must be signed in to change notification settings - Fork 288
Description
Summary
While creating a custom Microsoft.Testing.Platform extension and having to rely on the existing IConfiguration abstraction, we realized that its current public API surface is too restrictive, with only a single indexer for getting a specific key or section as a string.
Because of this limiting API, it is currently not possible to obtain a list of dynamic keys under a given section.
Background and Motivation
While creating a custom extension described in:
We had to rely on hacks to be able to know all possible keys under a json section so that we could then index into each key specifically.
Give the following custom node:
{
"environmentVariables": {
"VAR1": "a",
"VAR2": "b",
"VAR3": "c",
}
}The current indexer API only allows us to make 2 calls:
configuration["environmentVariables"], which returns a rawstringwith the entire section below it. This would force us to use something like Json deserialization to be useful, completely defeating the purpose of the managedIConfigurationin the first placeconfiguration["environmentVariables:VAR1"]. Correctly returns the "VAR1" child node, but we have to know that "VAR1" exists beforehand.
Due to this constraint, we were forced to create a hack to adapt our code.
Proposed Feature
The API should either expose all its parsed keys/subkeys, or have a way to navigate into child sections and then get the keys for that section like the Microsoft.Extensions.Configuration IConfiguration allows.
Alternative Designs
This is what we went with:
{
"environmentVariablesKeys": "VAR1,VAR2,VAR3",
"environmentVariables": {
"VAR1": "a",
"VAR2": "b",
"VAR3": "c",
}
}A new CSV node was added to list all possible keys under the "environmentVariables" section. We then read and parse this entry first, to be able to then specifically index into each key using the syntax specified on 2 above.
This is obviously less than ideal and can lead to consistency problems and unneeded complexity.