.net core获取appsettings CustomSettings

private static string GetCustomSettings(string key)
        {
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                         .Build();

            return config.GetSection("CustomSettings").GetValue(key, string.Empty);
        }
        // 获取自定义value
        public static string WXWarningClosedTemplateID => GetCustomSettings("xxx");

猜你喜欢

转载自www.cnblogs.com/LTEF/p/10334095.html