.Net6中对appsettings.json 的读取操作
假设当前 appsetting.json 文件存在以下内容
1.取单个值,比如Md5Key、CaptchaOptions下的CaptchaType
首先注入IConfiguration ,然后使用GetSection方法,如图
2.取链接字符
var dd3 = _configuration.GetConnectionString("SqlServerConnection");
3.取某个完整对象,比如JWTTokenOptions
先定义一个实体,包含他的所有字段
然后直接做绑定
4.通过全局注入的方式使用
首先在Program.cs 注入
然后在需要使用的地方