aspnet / MicrosoftConfigurationBuilders

Microsoft.Configuration.Builders
MIT License
122 stars 61 forks source link

How I can map direct from json to section? #162

Closed dmitriy-pisarevskiy closed 2 years ago

dmitriy-pisarevskiy commented 3 years ago

Hey! How I can map directly from json to ConfigurationSection? Most likely how you did with connectionStrings, but only on root element.

Example JSON file:

{
  "ApiConfiguration ": {
    "Setting1": "aaaa",
    "Setting2": "bbbb"
  },
}

Section ApiConfiguration class nested from ConfigurationSection

<ApiConfiguration configBuilders="appSettingsJson" />

must got as result something like xml

<ApiConfiguration Setting1="aaaa" Setting2="bbbb" />
dmitriy-pisarevskiy commented 3 years ago

looks like I found something SectionHandler<T>

StephenMolloy commented 2 years ago

Yes, SectionHandler<T> is the way to handle this scenario. Traditionally, a section handler would iterate over the child nodes of its given section rather than the attributes of the section node... but that's a choice made by the section handler. If your 'ApiConfiguration' section expects settings as attributes, then this is the correct way to do it.