using Microsoft.Extensions.Configuration;
#region 读配置信息
/// <summary>
/// AccessKeyId
/// </summary>
public readonly string AccessKeyId = "";
/// <summary>
/// AccessKeySecret
/// </summary>
public readonly string AccessKeySecret = "";
/// <summary>
/// Endping
/// </summary>
public readonly string Endping = "";
/// <summary>
/// 桶名
/// </summary>
public readonly string BucketName = "";
/// <summary>
/// 文件目录名 XW_WebFile/
/// </summary>
public readonly string DirectoryName = "";
/// <summary>
/// pg连接字符串
/// </summary>
public readonly string PgConnectionString = "";
#endregion 读配置信息
private readonly IConfiguration _configuration;
public HomeController(IConfiguration configuration)
{
_configuration = configuration;
AccessKeyId = _configuration["AccessKeyId"];
AccessKeySecret = _configuration["AccessKeySecret"];
Endping = _configuration["Endping"];
BucketName = _configuration["BucketName"];
DirectoryName = _configuration["DirectoryName"];
PgConnectionString = _configuration["ConnectionStrings:PostgreSQL"];
//构造函数退出后,不能分配 readonly 字段
}
c# - - - 控制器Controller读取配置文件
原创
©著作权归作者所有:来自51CTO博客作者zicl的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章