.NETコアstartup.csの強く型付けされたオブジェクトにappsettings.jsonセクションを読み込むことに慣れています。たとえば:.NETコアの辞書にappsetting.jsonセクションを読み込む方法は?
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."
}
はコントローラにMobileConfigInfoを注入するIOptionsパターンを使用し、次いでMobileConfigInfo辞書オブジェクトにこのデータをロードしてする方法はありますか?
がうーんASP.NETについて本当にこの質問をイマイチありません.NETコアではなく、コアですか?誤解を招くタイトルのビット。 – nashwan