I would like to create a hierarchical in-memory configuration along the lines of using a nested dictionary to populate the IConfiguration
. My current approach is something like this.
I have a dictionary like this:
var inMemConfig = new Dictionary<string, object>();
inMemConfig["section1"] = new Dictionary<string, string>();
inMemConfig["section2"] = new Dictionary<string, object>();
inMemConfig["deepNest"] = new Dictionary<string, object>();
// Excluding a cast below:
inMemConfig["deepNest"]["list"] = new List<Dictionary<string, string>>();
inMemConfig["deepNest"]["dict"] = new Dictionary<string string>();
After populating the above dictionary, I try to use ConfigurationBuilder
like below.
var builder = new ConfigurationBuilder();
var configuration = builder.AddInMemoryCollection(inMemConfig).Build();
This obviously give the compiler error that inMemConfig
needs to be of type: IEnumerable<KeyValuePair<string, string>>
.
Is it not possible to create hierarchical in-memory configurations and if so, any pointers in the right direction are much appreciated. Thanks.