| | |
| | | namespace PBS.BLL.WE |
| | | using System.Reflection; |
| | | using Yw; |
| | | |
| | | namespace PBS.BLL.WE |
| | | { |
| | | /// <summary> |
| | | /// CAL辅助类 |
| | |
| | | public static T CreateCAL<T>() |
| | | { |
| | | var type = Settings.WEParasHelper.WE.CAL.CALType; |
| | | return Yw.CALFactory.CreateCAL<T>(type); |
| | | return CreateCAL<T>(type); |
| | | } |
| | | |
| | | public static I CreateCAL<I>(string SourceType = "HttpClient", bool EnableCache = true, int CacheTime = 10) |
| | | { |
| | | Type typeFromHandle = typeof(I); |
| | | string @namespace = typeFromHandle.Namespace; |
| | | string name = typeFromHandle.Name; |
| | | string name2 = typeFromHandle.Assembly.GetName().Name; |
| | | string key = $"Yw.CALFactory-{SourceType}-{name2}-{@namespace}-{name}"; |
| | | I val = MemoryCacheHelper.Get<I>(key); |
| | | if (val != null) |
| | | { |
| | | return val; |
| | | } |
| | | |
| | | string typeName = $"{@namespace}.{SourceType}.{name.Remove(0, 1)}"; |
| | | val = (I)Assembly.Load(name2).CreateInstance(typeName); |
| | | if (val == null) |
| | | { |
| | | return val; |
| | | } |
| | | |
| | | if (EnableCache) |
| | | { |
| | | MemoryCacheHelper.Set(key, val, CacheTime); |
| | | } |
| | | |
| | | return val; |
| | | } |
| | | } |
| | | } |
| | | } |