diff --git a/WarehouseMgr/Tnb.WarehouseMgr/PcStroageService.cs b/WarehouseMgr/Tnb.WarehouseMgr/PcStroageService.cs index ae18e09f..f90c24f0 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/PcStroageService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/PcStroageService.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Dynamic; using System.Linq; using System.Reflection; using System.Text; @@ -15,25 +17,20 @@ namespace Tnb.WarehouseMgr [Caller("web")] public class PcStroageService : IWHStorageService { - private static Dictionary _serviceMap = new Dictionary(StringComparer.OrdinalIgnoreCase); + private static Dictionary> _serviceCallbackMap = new(StringComparer.OrdinalIgnoreCase); static PcStroageService() { - var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && !typeof(IPdaStroage).IsAssignableFrom(u) && u.IsSubclassOf(typeof(BaseWareHouseService))).ToList(); - foreach (var serviceType in serviceTypes) - { - var bizTypeId = serviceType.GetCustomAttribute()?.BizTypeId; - if (!bizTypeId.IsNullOrEmpty()) - { - _serviceMap[bizTypeId!] = (BaseWareHouseService)App.GetService(serviceType)!; - } - } + _serviceCallbackMap = App.EffectiveTypes.AsParallel().Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && !typeof(IPdaStroage).IsAssignableFrom(u) + && u.IsSubclassOf(typeof(BaseWareHouseService)) && u.GetCustomAttribute() != null) + .ToDictionary(x => x.GetCustomAttribute().BizTypeId, + x => (Func)Delegate.CreateDelegate(typeof(Func), App.GetService(x), x.GetMethod(nameof(WareHouseService.ModifyAsync)))); } public async Task Do(WareHouseUpInput input) { - if (_serviceMap.ContainsKey(input.bizTypeId)) + if (_serviceCallbackMap.ContainsKey(input.bizTypeId)) { - await _serviceMap[input.bizTypeId].ModifyAsync(input); + await _serviceCallbackMap[input.bizTypeId].Invoke(input); } } }