手动启动,定时新增字典缓存,避免多次反射影响性能
This commit is contained in:
@@ -62,25 +62,17 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
static BaseWareHouseService()
|
||||
{
|
||||
//_stroageMapLazy = new Lazy<Dictionary<string, IWHStorageService>>(() =>
|
||||
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList();
|
||||
foreach (var serviceType in serviceTypes)
|
||||
{
|
||||
//Dictionary<string, IWHStorageService> map = new(StringComparer.OrdinalIgnoreCase);
|
||||
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList();
|
||||
foreach (var serviceType in serviceTypes)
|
||||
var callerName = serviceType.GetCustomAttribute<CallerAttribute>()?.Name ?? string.Empty;
|
||||
if (!callerName.IsNullOrEmpty())
|
||||
{
|
||||
var callerName = serviceType.GetCustomAttribute<CallerAttribute>()?.Name ?? string.Empty;
|
||||
if (!callerName.IsNullOrEmpty())
|
||||
{
|
||||
var obj = Activator.CreateInstance(serviceType) as IWHStorageService;
|
||||
if (obj == null) continue;
|
||||
_storeMap[callerName] = obj;
|
||||
}
|
||||
var obj = Activator.CreateInstance(serviceType) as IWHStorageService;
|
||||
if (obj == null) continue;
|
||||
_storeMap[callerName] = obj;
|
||||
}
|
||||
//return map;
|
||||
}
|
||||
//);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected Task<ClaimsPrincipal> GetUserIdentity(string? asscessToken = null)
|
||||
|
||||
@@ -144,6 +144,7 @@ public class OAuthService : IDynamicApiController, ITransient
|
||||
private readonly IMHandler _imHandler;
|
||||
|
||||
private readonly BackgroundService _backgroundService; //added by ly on 20230916
|
||||
private static Dictionary<string, bool> _hostSvcRun = new();
|
||||
|
||||
|
||||
|
||||
@@ -294,11 +295,17 @@ public class OAuthService : IDynamicApiController, ITransient
|
||||
//modify by ly on 20230918 登录成功后启动定时服务
|
||||
if (!userId.IsNullOrWhiteSpace())
|
||||
{
|
||||
var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted");
|
||||
if (isStartedProperty?.GetValue(_backgroundService) is bool isStarted && !isStarted)
|
||||
if (!_hostSvcRun.TryGetValue("IsStarted", out bool isStarted))
|
||||
{
|
||||
var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted");
|
||||
isStarted = Convert.ToBoolean(isStartedProperty?.GetValue(_backgroundService));
|
||||
_hostSvcRun["IsStarted"] = isStarted;
|
||||
}
|
||||
if (!isStarted)
|
||||
{
|
||||
await _backgroundService.StartAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user