ASP.NET Core—access Configuration from static class

后端 未结 13 1984
我在风中等你
我在风中等你 2021-02-01 00:27

I want a simple static class that accesses the Configuration object. All the config info is already read in from the appsettings.json file in the Startup class. I just need an e

13条回答
  •  抹茶落季
    2021-02-01 00:33

    The IConfiguration is Injectable anywhere within the Project. But in the case of static class, the option I am using and maybe only approach... var Configuration = new ConfigurationBuilder() .AddUserSecrets() .Build(); And, you can add required section, such in this code block above, I added 'UserSecrets'.

提交回复
热议问题