diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Database/ScopedDbCurrent.cs b/src/Snap.Hutao/Snap.Hutao/Core/Database/ScopedDbCurrent.cs index 27a8c5c5..271ee806 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Database/ScopedDbCurrent.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Database/ScopedDbCurrent.cs @@ -38,6 +38,11 @@ internal sealed partial class ScopedDbCurrent return; } + if (serviceProvider.IsDisposedSlow()) + { + return; + } + // TODO: Troubeshooting why the serviceProvider will NRE using (IServiceScope scope = serviceProvider.CreateScope()) { @@ -92,6 +97,11 @@ internal sealed partial class ScopedDbCurrent return; } + if (serviceProvider.IsDisposedSlow()) + { + return; + } + // TODO: Troubeshooting why the serviceProvider will NRE using (IServiceScope scope = serviceProvider.CreateScope()) { diff --git a/src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/EnumerableServiceExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/EnumerableServiceExtension.cs deleted file mode 100644 index 44ddf98d..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/EnumerableServiceExtension.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Snap.Hutao.Core.DependencyInjection.Abstraction; -using System.Runtime.CompilerServices; - -namespace Snap.Hutao.Core.DependencyInjection; - -/// -/// 服务集合扩展 -/// -internal static class EnumerableServiceExtension -{ - /// - /// 选择对应的服务 - /// - /// 服务类型 - /// 服务集合 - /// 是否为海外服/Hoyolab - /// 对应的服务 - [Obsolete("该方法会导致不必要的服务实例化")] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TService Pick(this IEnumerable services, bool isOversea) - where TService : IOverseaSupport - { - return services.Single(s => s.IsOversea == isOversea); - } - - /// - /// 选择对应的服务 - /// - /// 服务类型 - /// 服务提供器 - /// 是否为海外服/Hoyolab - /// 对应的服务 - [Obsolete("该方法会导致不必要的服务实例化")] - public static TService PickRequiredService(this IServiceProvider serviceProvider, bool isOversea) - where TService : IOverseaSupport - { - return serviceProvider.GetRequiredService>().Pick(isOversea); - } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/ServiceProviderExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/ServiceProviderExtension.cs index f7d15aa4..d0bc7384 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/ServiceProviderExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/DependencyInjection/ServiceProviderExtension.cs @@ -16,4 +16,10 @@ internal static class ServiceProviderExtension { return ActivatorUtilities.CreateInstance(serviceProvider, parameters); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsDisposedSlow(this IServiceProvider serviceProvider) + { + return serviceProvider.GetType().GetField("_disposed")?.GetValue(serviceProvider) is true; + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Extension/UnsafeDateTimeOffset.cs b/src/Snap.Hutao/Snap.Hutao/Core/UnsafeDateTimeOffset.cs similarity index 95% rename from src/Snap.Hutao/Snap.Hutao/Extension/UnsafeDateTimeOffset.cs rename to src/Snap.Hutao/Snap.Hutao/Core/UnsafeDateTimeOffset.cs index 854b29eb..92b408dc 100644 --- a/src/Snap.Hutao/Snap.Hutao/Extension/UnsafeDateTimeOffset.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/UnsafeDateTimeOffset.cs @@ -1,7 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. -namespace Snap.Hutao.Extension; +namespace Snap.Hutao.Core; internal struct UnsafeDateTimeOffset { diff --git a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGF.cs b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGF.cs index a29b8471..1733be16 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGF.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/InterChange/GachaLog/UIGF.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Core; using Snap.Hutao.Web.Hoyolab; using System.Runtime.InteropServices; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Common/Announcement/AnnouncementWrapper.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Common/Announcement/AnnouncementWrapper.cs index ce675358..0d32391e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Common/Announcement/AnnouncementWrapper.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Common/Announcement/AnnouncementWrapper.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Core; using Snap.Hutao.Web.Response; namespace Snap.Hutao.Web.Hoyolab.Hk4e.Common.Announcement;