2018年6月18日月曜日

appsettings.jsonを取得

appsettings.json
{
  "Setting": {
    "Name" : "FooBar",
    "Age"  : 20
  }
}

Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    services.Configure(Configuration.GetSection("Hogehoge"));
}

Models/Hogehoge.cs
public class Hogehoge
{
  public string Name { get; set; }
  public int Age { get; set; }
}

Controllers/HomeController.cs
public HomeController(IOptions option){
    //option.Value.Name
    //option.Value.Age
}

0 件のコメント:

コメントを投稿