0条评论
还没有人评论过~
假定有这样一个JSON
{ "appSettings": { "Keep": "1", "DefaultConnStr": "DeafultConnection" }, "ConnectionStrings": { "DeafultConnection": "Provider=mssql;", "ModuleConnection": "Provider=mssql;", "WeChatConnection": "Provider=mssql;", "MySqlConnection": "Provider=mysql;" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*" }
现在需要读取 ConnectionStrings 中所有节点 (且事先并不知道这个节点有几个)
在.NetFramework中知道如何操作 , 突然切换过来有点不知所措 .
var connectionStringsList = builder.Build().GetSection("ConnectionStrings").AsEnumerable(true);
foreach(var item in connectionStringsList )
item.key //DeafultConnection
item.value // Provider=mssql;
参考 Get Multiple Connection Strings in appsettings.json without EF