ASP.NET Core 如何和读取配置文件中的内容?
可以有两种方式,可以通过IConfiguration接口来读取;
有可以定义根据配置文件结构一致的实体对象,来绑定到对象中去;或者通过1写入,2注入读取
必须保证:DBConnectionOption和配置文件的内容结构一致;
1. services.Configure<DBConnectionOption>(Configuration.GetSection("ConnectionStrings"));//注入多个链接
2.private DBConnectionOption dBConnections = null;
private DbContext _Context = null;
public DbContextFactory(DbContext context, IOptions<DBConnectionOption> options)
{
_Context = context;
dBConnections = options.Value;
}
本文介绍了ASP.NET Core中两种常见的配置文件读取方法:使用IConfiguration接口和定义与配置文件结构一致的实体对象进行绑定。同时强调了实体类与配置文件结构保持一致的重要性。
8440

被折叠的 条评论
为什么被折叠?



