🍒 fix(LazyServer): 修复懒加载服务异常

This commit is contained in:
喵你个汪呀 2025-09-03 08:23:41 +08:00
parent a91dd7f134
commit 5beb7d7027

View File

@ -11,7 +11,7 @@ namespace Admin.NET.Core;
/// </summary> /// </summary>
public class LazyHelper public class LazyHelper
{ {
private static readonly ConcurrentDictionary<Type, Lazy<object>> Cache = new(); private static readonly ConcurrentDictionary<Type, dynamic> Cache = new();
/// <summary> /// <summary>
/// 获取服务 /// 获取服务
@ -22,8 +22,7 @@ public class LazyHelper
{ {
try try
{ {
var lazy = Cache.GetOrAdd(typeof(T), _ => new Lazy<object>(() => App.GetService<T>())); return Cache.GetOrAdd(typeof(T), _ => new Lazy<T>(() => App.GetService<T>()));
return (Lazy<T>)(object)lazy;
} }
catch (Exception) catch (Exception)
{ {