优化配置文件查询
This commit is contained in:
parent
3981fa2303
commit
e98bde7ad5
78
Infrastructure/AppSettings.cs
Normal file
78
Infrastructure/AppSettings.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Infrastructure
|
||||
{
|
||||
public class AppSettings
|
||||
{
|
||||
static IConfiguration Configuration { get; set; }
|
||||
|
||||
public AppSettings(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 封装要操作的字符
|
||||
/// </summary>
|
||||
/// <param name="sections">节点配置</param>
|
||||
/// <returns></returns>
|
||||
public static string App(params string[] sections)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sections.Any())
|
||||
{
|
||||
return Configuration[string.Join(":", sections)];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归获取配置信息数组
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="sections"></param>
|
||||
/// <returns></returns>
|
||||
public static List<T> App<T>(params string[] sections)
|
||||
{
|
||||
List<T> list = new();
|
||||
// 引用 Microsoft.Extensions.Configuration.Binder 包
|
||||
Configuration.Bind(string.Join(":", sections), list);
|
||||
return list;
|
||||
}
|
||||
public static T Bind<T>(string key, T t)
|
||||
{
|
||||
Configuration.Bind(key, t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public static T GetAppConfig<T>(string key, T defaultValue = default)
|
||||
{
|
||||
T setting = (T)Convert.ChangeType(Configuration[key], typeof(T));
|
||||
var value = setting;
|
||||
if (setting == null)
|
||||
value = defaultValue;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置文件
|
||||
/// </summary>
|
||||
/// <param name="key">eg: WeChat:Token</param>
|
||||
/// <returns></returns>
|
||||
public static string GetConfig(string key)
|
||||
{
|
||||
return Configuration[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ namespace Infrastructure
|
||||
Instance = new ConfigUtils();
|
||||
}
|
||||
|
||||
public static ConfigUtils Instance { get; private set; }
|
||||
public static ConfigUtils Instance { get; }
|
||||
#endregion
|
||||
private static IConfiguration Configuration { get; set; }
|
||||
|
||||
|
||||
@ -237,7 +237,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
|
||||
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
|
||||
|
||||
dto.DbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.ConnBusDbType, 0);
|
||||
dto.DbType = AppSettings.GetAppConfig(OptionsSetting.ConnBusDbType, 0);
|
||||
dto.GenTable = genTableInfo;
|
||||
dto.IsPreview = true;
|
||||
//生成代码
|
||||
@ -263,7 +263,7 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
|
||||
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
|
||||
|
||||
dto.DbType = ConfigUtils.Instance.GetAppConfig(OptionsSetting.ConnBusDbType, 0);
|
||||
dto.DbType = AppSettings.GetAppConfig(OptionsSetting.ConnBusDbType, 0);
|
||||
dto.GenTable = genTableInfo;
|
||||
//自定义路径
|
||||
if (genTableInfo.GenType == "1")
|
||||
|
||||
@ -57,7 +57,7 @@ namespace ZR.Admin.WebApi.Filters
|
||||
HasPermi = perms.Exists(f => f.ToLower() == Permission.ToLower());
|
||||
}
|
||||
|
||||
bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false);
|
||||
bool isDemoMode = AppSettings.GetAppConfig("DemoMode", false);
|
||||
|
||||
//演示公开环境屏蔽权限
|
||||
string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send", "export", "upload", "common" };
|
||||
|
||||
@ -71,8 +71,9 @@ namespace ZR.Admin.WebApi.Framework
|
||||
/// <returns></returns>
|
||||
public static TokenValidationParameters ValidParameters()
|
||||
{
|
||||
JwtSettings jwtSettings = new JwtSettings();
|
||||
ConfigUtils.Instance.Bind("JwtSettings", jwtSettings);
|
||||
JwtSettings jwtSettings = new();
|
||||
AppSettings.Bind("JwtSettings", jwtSettings);
|
||||
|
||||
if (jwtSettings == null || jwtSettings.SecretKey.IsEmpty())
|
||||
{
|
||||
throw new Exception("JwtSettings获取失败");
|
||||
|
||||
@ -44,7 +44,8 @@ namespace ZR.Admin.WebApi
|
||||
});
|
||||
});
|
||||
//Ïû³ýError unprotecting the session cookie¾¯¸æ
|
||||
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection"));
|
||||
services.AddDataProtection()
|
||||
.PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection"));
|
||||
//ÆÕͨÑéÖ¤Âë
|
||||
services.AddHeiCaptcha();
|
||||
services.AddSession();
|
||||
@ -130,12 +131,12 @@ namespace ZR.Admin.WebApi
|
||||
private void InjectServices(IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddAppService();
|
||||
|
||||
services.AddSingleton(new AppSettings(configuration));
|
||||
//¿ªÆô¼Æ»®ÈÎÎñ
|
||||
services.AddTaskSchedulers();
|
||||
//³õʼ»¯db
|
||||
DbExtension.AddDb(configuration);
|
||||
|
||||
|
||||
//×¢²áREDIS ·þÎñ
|
||||
Task.Run(() =>
|
||||
{
|
||||
|
||||
@ -78,7 +78,7 @@ namespace ZR.CodeGenerator
|
||||
InitJntTemplate(dto, replaceDto);
|
||||
replaceDto.VueViewListHtml = GenerateVueTableList();
|
||||
replaceDto.VueQueryFormHtml = GenerateVueQueryForm();
|
||||
|
||||
|
||||
GenerateModels(replaceDto, dto);
|
||||
GenerateInputDto(replaceDto, dto);
|
||||
GenerateRepository(replaceDto, dto);
|
||||
@ -277,8 +277,8 @@ namespace ZR.CodeGenerator
|
||||
/// <returns></returns>
|
||||
public static string GetClassName(string tableName)
|
||||
{
|
||||
bool autoRemovePre = ConfigUtils.Instance.GetAppConfig(GenConstants.Gen_autoPre, false);
|
||||
string tablePrefix = ConfigUtils.Instance.GetAppConfig<string>(GenConstants.Gen_tablePrefix);
|
||||
bool autoRemovePre = AppSettings.GetAppConfig(GenConstants.Gen_autoPre, false);
|
||||
string tablePrefix = AppSettings.GetAppConfig<string>(GenConstants.Gen_tablePrefix);
|
||||
|
||||
if (!string.IsNullOrEmpty(tablePrefix) && autoRemovePre)
|
||||
{
|
||||
@ -364,7 +364,7 @@ namespace ZR.CodeGenerator
|
||||
ModuleName = "business",//导入默认模块名
|
||||
ClassName = GetClassName(tableName).FirstUpperCase(),
|
||||
BusinessName = tableName.UnderScoreToCamelCase().FirstUpperCase(),
|
||||
FunctionAuthor = ConfigUtils.Instance.GetConfig(GenConstants.Gen_author),
|
||||
FunctionAuthor = AppSettings.GetConfig(GenConstants.Gen_author),
|
||||
TableName = tableName,
|
||||
TableComment = desc,
|
||||
FunctionName = desc,
|
||||
|
||||
@ -23,8 +23,8 @@ namespace ZR.CodeGenerator
|
||||
/// <returns></returns>
|
||||
public SqlSugarClient GetSugarDbContext(string dbName = "")
|
||||
{
|
||||
string connStr = ConfigUtils.Instance.GetConfig(GenConstants.Gen_conn);
|
||||
int dbType = ConfigUtils.Instance.GetAppConfig(GenConstants.Gen_conn_dbType, 0);
|
||||
string connStr = AppSettings.GetConfig(GenConstants.Gen_conn);
|
||||
int dbType = AppSettings.GetAppConfig(GenConstants.Gen_conn_dbType, 0);
|
||||
|
||||
if (!string.IsNullOrEmpty(dbName))
|
||||
{
|
||||
|
||||
@ -8,10 +8,10 @@ namespace ZR.Common
|
||||
{
|
||||
public class AliyunOssHelper
|
||||
{
|
||||
static string accessKeyId = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:KEY");
|
||||
static string accessKeySecret = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:SECRET");
|
||||
static string endpoint = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:REGIONID");
|
||||
static string bucketName1 = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:bucketName");
|
||||
static string accessKeyId = AppSettings.GetConfig("ALIYUN_OSS:KEY");
|
||||
static string accessKeySecret = AppSettings.GetConfig("ALIYUN_OSS:SECRET");
|
||||
static string endpoint = AppSettings.GetConfig("ALIYUN_OSS:REGIONID");
|
||||
static string bucketName1 = AppSettings.GetConfig("ALIYUN_OSS:bucketName");
|
||||
|
||||
/// <summary>
|
||||
/// 上传到阿里云
|
||||
|
||||
@ -10,8 +10,8 @@ namespace ZR.Common.Cache
|
||||
|
||||
public static void Initalize()
|
||||
{
|
||||
Cache = new CSRedisClient(ConfigUtils.Instance.GetConfig("RedisServer:Cache"));
|
||||
Session = new CSRedisClient(ConfigUtils.Instance.GetConfig("RedisServer:Session"));
|
||||
Cache = new CSRedisClient(AppSettings.GetConfig("RedisServer:Cache"));
|
||||
Session = new CSRedisClient(AppSettings.GetConfig("RedisServer:Session"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ namespace ZR.Common
|
||||
|
||||
public MailHelper()
|
||||
{
|
||||
ConfigUtils.Instance.Bind("MailOptions", mailOptions);
|
||||
AppSettings.Bind("MailOptions", mailOptions);
|
||||
FromEmail = mailOptions.From;
|
||||
Smtp = mailOptions.Smtp;
|
||||
FromPwd = mailOptions.Password;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace ZR.Service.System
|
||||
[AppService(ServiceType = typeof(ISysFileService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class SysFileService : BaseService<SysFile>, ISysFileService
|
||||
{
|
||||
private string domainUrl = ConfigUtils.Instance.GetConfig("ALIYUN_OSS:domainUrl");
|
||||
private string domainUrl = AppSettings.GetConfig("ALIYUN_OSS:domainUrl");
|
||||
private readonly SysFileRepository SysFileRepository;
|
||||
|
||||
public SysFileService(SysFileRepository repository) : base(repository)
|
||||
|
||||
@ -340,4 +340,21 @@ export default {
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
</script>
|
||||
<style scoped>
|
||||
|
||||
.el-avatar {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
background: #ccc;
|
||||
color: #fff;
|
||||
white-space: nowrap;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
vertical-align: middle;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
border-radius: 16px;
|
||||
}
|
||||
</style>
|
||||
Loading…
x
Reference in New Issue
Block a user