Я знаком с загрузкой раздела appsettings.json в строго типизированный объект в .NET Core startup.cs. Например:
public class CustomSection
{
public int A {get;set;}
public int B {get;set;}
}
//In Startup.cs
services.Configure<CustomSection>(Configuration.GetSection("CustomSection"));
//Inject an IOptions instance
public HomeController(IOptions<CustomSection> options)
{
var settings = options.Value;
}
У меня есть раздел appsettings.json, где пары ключ/значение будут меняться по количеству и имени с течением времени. Поэтому нецелесообразно записывать имена свойств класса в класс, поскольку новые пары ключ/значение потребуют изменения кода в классе. Небольшая выборка некоторых пар ключ/значение:
"MobileConfigInfo": {
"appointment-confirmed": "We've booked your appointment. See you soon!",
"appointments-book": "New Appointment",
"appointments-null": "We could not locate any upcoming appointments for you.",
"availability-null": "Sorry, there are no available times on this date. Please try another."
}
Есть ли способ загрузить эти данные в объект Dictionary MobileConfigInfo, а затем использовать шаблон IOptions для ввода MobileConfigInfo в контроллер?