.SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddOptions(); // Configuration から動的に取ってくる services.Configure<MyOption>(Configuration.GetSection("MyOption")); // コード内で設定を行う services.Configure<MyOption>(options => { options.IntValue = 123; options.StrValue = "kazuakix"; }); // Add framework services. services.AddMvc(); } public class HomeController : Controller { // IOptions<T> は DI で解決される public HomeController(IOptions<MyOption> optionAccessor) { // MyOption のインスタンスを貰う _myOption = optionAccessor.Value; } private readonly MyOption _myOption; } { "MyOption": { "IntValue": 123, "StrValue": "kazuakix" } } appsettings.json