diff --git a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs index d31deb82..b822a7a6 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs @@ -62,25 +62,17 @@ namespace Tnb.WarehouseMgr static BaseWareHouseService() { - //_stroageMapLazy = new Lazy>(() => + var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList(); + foreach (var serviceType in serviceTypes) { - //Dictionary 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()?.Name ?? string.Empty; + if (!callerName.IsNullOrEmpty()) { - var callerName = serviceType.GetCustomAttribute()?.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 GetUserIdentity(string? asscessToken = null) diff --git a/system/Tnb.OAuth/OAuthService.cs b/system/Tnb.OAuth/OAuthService.cs index 31ef6145..a1d76f02 100644 --- a/system/Tnb.OAuth/OAuthService.cs +++ b/system/Tnb.OAuth/OAuthService.cs @@ -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 _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); } + }