ASP.NET Core—access Configuration from static class

后端 未结 13 2017
我在风中等你
我在风中等你 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:35

    If you are using environment variables as your configuration, you can access the environment variable directly rather than via the configuration object.

    using System;
    
    namespace My.Example
    {
        public static class GetPaths
        {
            private static readonly string MyPATH = 
                Environment.GetEnvironmentVariable("PATH");
    
            private static readonly string MySpecialPath =
                Environment.GetEnvironmentVariable("PREFIX_SpecialPath");
            ...
        }
    }
    

提交回复
热议问题