-
Notifications
You must be signed in to change notification settings - Fork 201
Add support for collections/arrays #125
Comments
Curious if anyone's thought about this at all. I see it overlaps with #115 so I'd be OK with closing this one and just following there. Either way, it'd be nice to know if this is planned or not so I know what to do with my consuming code. |
I see #115 is in planning so I'll close this one. |
Unfortunately there is no way to read arrays from XML (FormatException). Arrays are supported in JSON and INI configs. |
You can do arrays in XML, you just have to give the XML element a <root>
<node name="0" value="first array element" />
<node name="1" value="second array element" />
</root> |
@tillig Thanks for the answer, but what if I need to use "name" attribute for other purposes? |
The The whole way arrays work is that the "name" of the element is the array index. Iterating through "arrays" in the configuration source can be done with a foreach, but if you look at each child you're iterating through, you'll see the "key" on the child property is actually the array index as a string. That's done so INI files can "fake" arrays ("ordinal collections"), so JSON array support works... and this is how XML support also works. If that means you need to nest elements, do that. <root>
<node name="0">
<value name="first" />
</node>
<node name="1">
<value name="second" />
</node>
</root> |
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:
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...
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?
The text was updated successfully, but these errors were encountered: