Skip to content

Commit 2e016ad

Browse files
committed
Move Concurrentdictionary to ReflectionCacheSet.Shared.Internal.GenericTypeDefinitionByType
1 parent 2748277 commit 2e016ad

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Autofac/Core/InternalReflectionCaches.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ internal class InternalReflectionCaches
5454
/// </summary>
5555
public ReflectionCacheDictionary<Type, ConstructorInfo[]> DefaultPublicConstructors { get; }
5656

57+
public ReflectionCacheDictionary<Type, Type> GenericTypeDefinitionByType { get; }
58+
5759
/// <summary>
5860
/// Initializes a new instance of the <see cref="InternalReflectionCaches"/> class.
5961
/// </summary>
@@ -72,5 +74,6 @@ public InternalReflectionCaches(ReflectionCacheSet set)
7274
AutowiringPropertySetters = set.GetOrCreateCache<ReflectionCacheDictionary<PropertyInfo, Action<object, object?>>>(nameof(AutowiringPropertySetters));
7375
AutowiringInjectableProperties = set.GetOrCreateCache<ReflectionCacheDictionary<Type, IReadOnlyList<PropertyInfo>>>(nameof(AutowiringInjectableProperties));
7476
DefaultPublicConstructors = set.GetOrCreateCache<ReflectionCacheDictionary<Type, ConstructorInfo[]>>(nameof(DefaultPublicConstructors));
77+
GenericTypeDefinitionByType = set.GetOrCreateCache<ReflectionCacheDictionary<Type, Type>>(nameof(GenericTypeDefinitionByType));
7578
}
7679
}

src/Autofac/Features/OpenGenerics/OpenGenericServiceBinder.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ public static bool TryBindOpenGenericTypedService(
6969
return false;
7070
}
7171

72-
private static readonly ConcurrentDictionary<Type, Type> GenericTypeDefinitionByType = new();
73-
private static readonly Func<Type, Type> GenericTypeDefinitionFactory = type => type.GetGenericTypeDefinition();
74-
75-
private static Type GetGenericTypeDefinition(Type type) => GenericTypeDefinitionByType.GetOrAdd(type, GenericTypeDefinitionFactory);
72+
private static Type GetGenericTypeDefinition(Type type) => ReflectionCacheSet.Shared.Internal.GenericTypeDefinitionByType.GetOrAdd(type, static t => t.GetGenericTypeDefinition());
7673

7774
/// <summary>
7875
/// Given a closed generic service (that is being requested), creates a regular delegate callback

0 commit comments

Comments
 (0)