手动启动,定时新增字典缓存,避免多次反射影响性能

This commit is contained in:
alex
2023-09-18 15:07:04 +08:00
parent 0ac46b6e65
commit 6cc0529d60
2 changed files with 16 additions and 17 deletions

View File

@@ -62,9 +62,6 @@ namespace Tnb.WarehouseMgr
static BaseWareHouseService() static BaseWareHouseService()
{ {
//_stroageMapLazy = new Lazy<Dictionary<string, IWHStorageService>>(() =>
{
//Dictionary<string, IWHStorageService> map = new(StringComparer.OrdinalIgnoreCase);
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList(); var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList();
foreach (var serviceType in serviceTypes) foreach (var serviceType in serviceTypes)
{ {
@@ -76,11 +73,6 @@ namespace Tnb.WarehouseMgr
_storeMap[callerName] = obj; _storeMap[callerName] = obj;
} }
} }
//return map;
}
//);
} }
protected Task<ClaimsPrincipal> GetUserIdentity(string? asscessToken = null) protected Task<ClaimsPrincipal> GetUserIdentity(string? asscessToken = null)

View File

@@ -144,6 +144,7 @@ public class OAuthService : IDynamicApiController, ITransient
private readonly IMHandler _imHandler; private readonly IMHandler _imHandler;
private readonly BackgroundService _backgroundService; //added by ly on 20230916 private readonly BackgroundService _backgroundService; //added by ly on 20230916
private static Dictionary<string, bool> _hostSvcRun = new();
@@ -293,12 +294,18 @@ public class OAuthService : IDynamicApiController, ITransient
//modify by ly on 20230918 登录成功后启动定时服务 //modify by ly on 20230918 登录成功后启动定时服务
if (!userId.IsNullOrWhiteSpace()) if (!userId.IsNullOrWhiteSpace())
{
if (!_hostSvcRun.TryGetValue("IsStarted", out bool isStarted))
{ {
var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted"); var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted");
if (isStartedProperty?.GetValue(_backgroundService) is bool isStarted && !isStarted) isStarted = Convert.ToBoolean(isStartedProperty?.GetValue(_backgroundService));
_hostSvcRun["IsStarted"] = isStarted;
}
if (!isStarted)
{ {
await _backgroundService.StartAsync(CancellationToken.None); await _backgroundService.StartAsync(CancellationToken.None);
} }
} }