//添加 json 文件路径 var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
//创建配置根对象
var configurationRoot = builder1.Build();
//读取到ioc IOptions<SuperAppsettings> setting 依赖注入
services.Configure<SuperAppsettings>(configurationRoot.GetSection("super")); // 依赖注入
原文地址:https://www.cnblogs.com/zxs-onestar/p/12084383.html
时间: 2024-10-08 03:58:18