This repository was archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 202
List of objects in json configuration issue #727
Copy link
Copy link
Closed
Description
I'm creating a json file that I wish to add in configuration through configuration.AddJsonFile()
with the following structure:
{
"JsonLocalizerOptions": {
"SupportedLanguages": [
{
"Identifier": "ro-MD",
"Name": "Romana"
}
]
}
}
then I have a POCO class for it:
public class JsonLocalizerOptions
{
#region Private backing fields (Default Values)
private List<Language> supportedLanguages = new List<Language>()
{
new Language
{
Identifier = "en",
Name = "English"
},
new Language
{
Identifier = "ro",
Name = "Română"
},
new Language
{
Identifier ="ru",
Name ="Русский"
}
};
#endregion
public JsonLocalizerOptions() { }
#region Public Properties
public List<Language> SupportedLanguages
{
get => supportedLanguages;
set => supportedLanguages = value;
}
#endregion
}
The problem is that when I call services.Configure<JsonLocalizerOptions>(Configuration.GetSection(nameof(JsonLocalizerOptions)))
the value
object from the setter of the property SupportedLanguages
contains the default list of the languages plus that one object from the json file. I think this is bizarre, I thought that when I call Configure
I should receive the data from the json file, not my current data appending that one from json or the same data from the private field even though the setter is accessed.
Is this really how it should work?
Metadata
Metadata
Assignees
Labels
No labels