ASP.NET 5 (vNext) - Configuration

前端 未结 3 1984
耶瑟儿~
耶瑟儿~ 2021-02-08 18:58

I am trying to learn ASP.NET 5. I am using it on Mac OS X. At this time, I have a config.json file that looks like the following:

config.json

         


        
3条回答
  •  孤城傲影
    2021-02-08 19:10

    Try use OptionsModel. it allows strong typed model binding to configuration.

    class AppSettings
    {
       public string SomeSetting {get;set;}
    }
    
    var configuration = new Configuration().AddJsonFile("config.json");
    var opt = ConfigurationBinder.Bind(configuration);
    opt.SomeSetting 
    

    Example: https://github.com/aspnet/Options/blob/dev/test/Microsoft.Framework.OptionsModel.Test/OptionsTest.cs#L80

提交回复
热议问题