Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Add support for collections/arrays #125

@tillig

Description

@tillig

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions