.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");
复制代码

 

posted @   Super-Yan  阅读(194)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示