diff --git a/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs b/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs
index 17fd94c467..7804cbbd98 100644
--- a/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs
+++ b/framework/src/Volo.Abp.Autofac/Autofac/Extensions/DependencyInjection/AutofacRegistration.cs
@@ -298,32 +298,4 @@ public static class AutofacRegistration
.ConfigureLifecycle(descriptor.Lifetime, null);
}
}
-
- ///
- /// Normalizes the implementation instance data between keyed and not keyed services.
- ///
- ///
- /// The to normalize.
- ///
- ///
- /// The appropriate implementation instance from the service descriptor.
- ///
- public static object? NormalizedImplementationInstance(this ServiceDescriptor descriptor)
- {
- return !descriptor.IsKeyedService ? descriptor.ImplementationInstance : descriptor.KeyedImplementationInstance;
- }
-
- ///
- /// Normalizes the implementation type data between keyed and not keyed services.
- ///
- ///
- /// The to normalize.
- ///
- ///
- /// The appropriate implementation type from the service descriptor.
- ///
- public static Type? NormalizedImplementationType(this ServiceDescriptor descriptor)
- {
- return !descriptor.IsKeyedService ? descriptor.ImplementationType : descriptor.KeyedImplementationType;
- }
}
diff --git a/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs b/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs
index 7301b0b7a9..16f5ba9a86 100644
--- a/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs
+++ b/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs
@@ -28,7 +28,7 @@ public static class ServiceCollectionCommonExtensions
{
return (T?)services
.FirstOrDefault(d => d.ServiceType == typeof(T))
- ?.ImplementationInstance;
+ ?.NormalizedImplementationInstance();
}
public static T GetSingletonInstance(this IServiceCollection services)
@@ -48,7 +48,7 @@ public static class ServiceCollectionCommonExtensions
foreach (var service in services)
{
- var factoryInterface = service.ImplementationInstance?.GetType()
+ var factoryInterface = service.NormalizedImplementationInstance()?.GetType()
.GetTypeInfo()
.GetInterfaces()
.FirstOrDefault(i => i.GetTypeInfo().IsGenericType &&
diff --git a/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceDescriptorExtensions.cs b/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceDescriptorExtensions.cs
new file mode 100644
index 0000000000..1a160edb54
--- /dev/null
+++ b/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceDescriptorExtensions.cs
@@ -0,0 +1,31 @@
+using System;
+
+namespace Microsoft.Extensions.DependencyInjection;
+
+///
+/// Extensions for working with .
+///
+public static class ServiceDescriptorExtensions
+{
+ ///
+ /// Normalizes the implementation instance data between keyed and not keyed services.
+ ///
+ ///
+ /// The to normalize.
+ ///
+ ///
+ /// The appropriate implementation instance from the service descriptor.
+ ///
+ public static object? NormalizedImplementationInstance(this ServiceDescriptor descriptor) => descriptor.IsKeyedService ? descriptor.KeyedImplementationInstance : descriptor.ImplementationInstance;
+
+ ///
+ /// Normalizes the implementation type data between keyed and not keyed services.
+ ///
+ ///
+ /// The to normalize.
+ ///
+ ///
+ /// The appropriate implementation type from the service descriptor.
+ ///
+ public static Type? NormalizedImplementationType(this ServiceDescriptor descriptor) => descriptor.IsKeyedService ? descriptor.KeyedImplementationType : descriptor.ImplementationType;
+}
diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceDescriptor.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceDescriptor.cs
new file mode 100644
index 0000000000..1b812fc4a2
--- /dev/null
+++ b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceDescriptor.cs
@@ -0,0 +1,29 @@
+using System;
+
+namespace Volo.Abp.DependencyInjection;
+
+public class CachedServiceDescriptor
+{
+ private object? Key { get; }
+
+ private Type ServiceType { get; }
+
+ public CachedServiceDescriptor(object? key, Type serviceType)
+ {
+ Key = key;
+ ServiceType = serviceType;
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return obj is CachedServiceDescriptor descriptor &&
+ Key == descriptor.Key &&
+ ServiceType == descriptor.ServiceType;
+ }
+
+ public override int GetHashCode()
+ {
+ var keyHashCode = Key?.GetHashCode() ?? 0;
+ return keyHashCode ^ ServiceType.GetHashCode();
+ }
+}
diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceProviderBase.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceProviderBase.cs
index 5e8d9d251a..774efedb9a 100644
--- a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceProviderBase.cs
+++ b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/CachedServiceProviderBase.cs
@@ -1,28 +1,29 @@
using System;
using System.Collections.Concurrent;
+using Microsoft.Extensions.DependencyInjection;
namespace Volo.Abp.DependencyInjection;
public abstract class CachedServiceProviderBase : ICachedServiceProviderBase
{
protected IServiceProvider ServiceProvider { get; }
- protected ConcurrentDictionary> CachedServices { get; }
+ protected ConcurrentDictionary> CachedServices { get; }
protected CachedServiceProviderBase(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
- CachedServices = new ConcurrentDictionary>();
- CachedServices.TryAdd(typeof(IServiceProvider), new Lazy