-
Notifications
You must be signed in to change notification settings - Fork 202
Add support for collections/arrays #125
Description
Using Microsoft.Framework.ConfigurationModel 1.0.0.0-rc1-10693.
Trying to convert the Autofac configuration system over to use the new configuration mechanism. Current Autofac configuration allows for a collection of classes to be registered via config, sometimes with different parameter sets, like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<modules>
<module type="ParameterizedModule">
<parameters>
<parameter name="message" value="First" />
</parameters>
</module>
<module type="ParameterizedModule">
<parameters>
<parameter name="message" value="Second" />
</parameters>
</module>
</modules>
</configuration>
Notice the module type is the same but the parameters provided are different.
This sort of configuration doesn't appear to be possible with the new XML or JSON implementations of configuration.
If I try loading this into the XML provider, I get an exception that the module type is duplicated.
For JSON, I'm not sure how I'd represent this without arrays. I originally thought it'd be something like this...
{
"modules": [
{
"type": "ParameterizedModule",
"parameters": [{ "name": "message", "value": "First"}]
},
{
"type": "ParameterizedModule",
"parameters": [{ "name": "message", "value": "Second"}]
}
]
}
But the JSON support doesn't support arrays (i.e., the Load
method in JsonConfigurationSource throws if it encounters an array)... and, as mentioned, XML throws on duplicate elements.
I've not seen anywhere in the docs how to handle this and I've not found any roadmap, but this seems like an important use case to me. Am I missing something? Is there a better way to handle this situation?