From 4754253e7c25c258c85e8ccaa5a27d4d15ac24e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 24 Feb 2022 20:27:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20ConfigUtils.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/ConfigUtils.cs | 61 ----------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 Infrastructure/ConfigUtils.cs diff --git a/Infrastructure/ConfigUtils.cs b/Infrastructure/ConfigUtils.cs deleted file mode 100644 index 432604c..0000000 --- a/Infrastructure/ConfigUtils.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using System; - -/// -/// 需要引用包 -/// Microsoft.Extensions.Configuration; -/// Microsoft.Extensions.DependencyInjection; -namespace Infrastructure -{ - public class ConfigUtils - { - #region 单例访问 - - static ConfigUtils() - { - Configuration = App.ServiceProvider.GetRequiredService(); - - if (Instance == null) - Instance = new ConfigUtils(); - } - - public static ConfigUtils Instance { get; } - #endregion - private static IConfiguration Configuration { get; set; } - - public T GetAppConfig(string key, T defaultValue = default(T)) - { - T setting = (T)Convert.ChangeType(Configuration[key], typeof(T)); - var value = setting; - if (setting == null) - value = defaultValue; - return value; - } - public T Bind(string key, T t) - { - Configuration.Bind(key, t); - - return t; - } - /// - /// 获取配置文件 - /// - /// eg: WeChat:Token - /// - public string GetConfig(string key) - { - return Configuration[key]; - } - - /// - /// 获取数据库字符串连接串 - /// - /// - /// - public string GetConnectionString(string key) - { - return Configuration.GetConnectionString(key); - } - } -}