BaseWareHouseService 类静态函数打回原形,改为延迟加载,以避免未登录使用用户情况

This commit is contained in:
alex
2023-10-09 09:32:34 +08:00
parent ac1c140e4a
commit 0300ea2598

View File

@@ -54,7 +54,7 @@ namespace Tnb.WarehouseMgr
private static Dictionary<string, IWHStorageService> _storeMap = new(StringComparer.OrdinalIgnoreCase);
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
private readonly ChannelWriter<NotifyMessage> _channelWriter;
public BaseWareHouseService(ChannelWriter<NotifyMessage>? channelWriter = default)
@@ -64,17 +64,23 @@ namespace Tnb.WarehouseMgr
static BaseWareHouseService()
{
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList();
foreach (var serviceType in serviceTypes)
_stroageMapLazy = new Lazy<Dictionary<string, IWHStorageService>>(() =>
{
var callerName = serviceType.GetCustomAttribute<CallerAttribute>()?.Name ?? string.Empty;
if (!callerName.IsNullOrEmpty())
Dictionary<string, IWHStorageService> map = new();
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList();
foreach (var serviceType in serviceTypes)
{
var obj = Activator.CreateInstance(serviceType) as IWHStorageService;
if (obj == null) continue;
_storeMap[callerName] = obj;
var callerName = serviceType.GetCustomAttribute<CallerAttribute>()?.Name ?? string.Empty;
if (!callerName.IsNullOrEmpty())
{
var obj = Activator.CreateInstance(serviceType) as IWHStorageService;
if (obj == null) continue;
map[callerName] = obj;
}
}
}
return map;
});
}
protected Task<ClaimsPrincipal> GetUserIdentity(string? asscessToken = null)
@@ -140,9 +146,9 @@ namespace Tnb.WarehouseMgr
[NonAction]
protected async Task DoUpdate(WareHouseUpInput input)
{
if (_storeMap.ContainsKey(input.loginType))
if (_stroageMapLazy.Value.ContainsKey(input.loginType))
{
await _storeMap[input.loginType].Do(input);
await _stroageMapLazy.Value[input.loginType].Do(input);
}
}
[NonAction]
@@ -229,7 +235,7 @@ namespace Tnb.WarehouseMgr
}
}
if (0 != ret)
return ;
return;
// sample setting.
PPLBUtility.B_Set_Originpoint(0, 0);
@@ -251,7 +257,7 @@ namespace Tnb.WarehouseMgr
PPLBUtility.B_Prn_Text(200, 50, 0, 2, 2, 2, 'N', code);
//barcode.
PPLBUtility.B_Prn_Barcode(50, 100, 0, "1", 3, 5, 70, 'B', code);//have a counter
// output.
// output.
PPLBUtility.B_Print_Out(1);// copy 2.
}
}