⚡ 优化功能
This commit is contained in:
parent
68d43240e7
commit
65543e651c
@ -45,17 +45,26 @@ namespace Infrastructure
|
||||
public static List<T> App<T>(params string[] sections)
|
||||
{
|
||||
List<T> list = new();
|
||||
// 引用 Microsoft.Extensions.Configuration.Binder 包
|
||||
Configuration.Bind(string.Join(":", sections), list);
|
||||
try
|
||||
{
|
||||
if (Configuration != null && sections.Any())
|
||||
{
|
||||
Configuration.Bind(string.Join(":", sections), list);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 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));
|
||||
@ -74,5 +83,16 @@ namespace Infrastructure
|
||||
{
|
||||
return Configuration[key];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置节点并转换成指定类型
|
||||
/// </summary>
|
||||
/// <typeparam name="T">节点类型</typeparam>
|
||||
/// <param name="key">节点路径</param>
|
||||
/// <returns>节点类型实例</returns>
|
||||
public static T Get<T>(string key)
|
||||
{
|
||||
return Configuration.GetSection(key).Get<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@ -16,7 +17,11 @@ namespace ZR.Admin.WebApi.Extensions
|
||||
/// <param name="services"></param>
|
||||
public static void AddAppService(this IServiceCollection services)
|
||||
{
|
||||
string[] cls = new string[] { "ZR.Repository", "ZR.Service", "ZR.Tasks" };
|
||||
var cls = AppSettings.Get<string[]>("InjectClass");
|
||||
if (cls == null || cls.Length <= 0)
|
||||
{
|
||||
throw new Exception("请更新appsettings类");
|
||||
}
|
||||
foreach (var item in cls)
|
||||
{
|
||||
Register(services, item);
|
||||
|
||||
@ -61,8 +61,8 @@ builder.Services.AddAuthentication(options =>
|
||||
});
|
||||
|
||||
//InternalApp.InternalServices = builder.Services;
|
||||
builder.Services.AddAppService();
|
||||
builder.Services.AddSingleton(new AppSettings(builder.Configuration));
|
||||
builder.Services.AddAppService();
|
||||
//开启计划任务
|
||||
builder.Services.AddTaskSchedulers();
|
||||
//初始化db
|
||||
|
||||
@ -18,7 +18,8 @@
|
||||
"SecretKey": "SecretKey-ZRADMIN.NET-20210101",
|
||||
"Expire": 1440 //jwt登录过期时间(分)
|
||||
},
|
||||
"InitDb": false,//是否初始化db
|
||||
"InjectClass": [ "ZR.Repository", "ZR.Service", "ZR.Tasks" ],//自动注入类
|
||||
"InitDb": false, //是否初始化db
|
||||
"DemoMode": false, //是否演示模式
|
||||
"Upload": {
|
||||
"uploadUrl": "http://localhost:8888", //本地存储资源访问路径
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user