/// <summary> /// 配置文件服务 /// </summary> public class AppConfigurtaionServices { /// <summary> /// 配置文件对象 /// </summary> public static IConfiguration Configuration { get; set; } static AppConfigurtaionServices() { var reloadOnChange = true; // 当appsettings.json被修改时重新加载 Configuration = new ConfigurationBuilder() .Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = reloadOnChange }) .Build(); } }
// 读取数据库连接配置项 var redisService = AppConfigurtaionServices.Configuration["ConnectionString:testdb"];
{ "ConnectionString": { "testdb": "server=localhost;port=3306;database=localtest;uid=root;pwd=123456;SslMode=None" } }
标签:core,AppConfigurtaionServices,读取,配置文件,reloadOnChange,ConnectionString,net,Config From: https://www.cnblogs.com/yu-xiansheng/p/17436491.html