I have the following appSettings.json file:
"SundrySettings": {
"CookieName": "Cookie",
"AccessGroup": "Software Development",
"Terminals" : {
"Raucherplatz" : "tablet1.local",
"Service" : "tablet2.local",
"Technik" : "tablet3.local",
"Technik" : "tablet4.local",
"Container" : "tablet5.local"
}
}
}
That I would like to load into the following structure:
public class Terminal
{
public string Name;
public string Description;
}
public class SundryOptions
{
public string CookieName { get; set; } = "dummy";
public string HRAccessGroup { get; set; } = "dummy";
public List<Terminal> Terminals;
}
that I would try to load using the following commands:
ServiceProvider sp = services.BuildServiceProvider();
SundryOptions sundryOptions = sp.GetService<IOptions<SundryOptions>>().Value;
The problem I have is that using Property Initialisers never sets the Terminals List correctly. I do need a list (and not a Dictionary) as the enties could be double i.e. Technik in my example.
I am assuming that I have some error in the Class -> I would be happy for any pointers.
Terminalclass you posted doesn't match theTerminalin the json file.Technikis a setting, not some name in a name/value pair. The path to that setting isSundrySettings::Terminals::Serviceand its value istablet2.local. I suspect you're trying to use the Configuration subsystem like a database?Technikwill throw too, because it's not unique. That's how the Configuration system works - each setting has a specific path and a value. Those settings can be mapped to strongly-typed objects. If the objects match the settings, this is trivial. If not, you'll have to write code to map one to the other