@@ -12,13 +12,13 @@ namespace AutoMapper.EquivalencyExpression
1212 public static class EquivalentExpressions
1313 {
1414 private static readonly
15- IDictionary < IConfigurationProvider , ConcurrentDictionary < TypePair , IEquivalentComparer > >
15+ ConcurrentDictionary < IConfigurationProvider , ConcurrentDictionary < TypePair , IEquivalentComparer > >
1616 EquivalentExpressionDictionary =
17- new Dictionary < IConfigurationProvider , ConcurrentDictionary < TypePair , IEquivalentComparer > > ( ) ;
17+ new ConcurrentDictionary < IConfigurationProvider , ConcurrentDictionary < TypePair , IEquivalentComparer > > ( ) ;
1818
1919 private static ConcurrentDictionary < TypePair , IEquivalentComparer > _equalityComparisonCache = new ConcurrentDictionary < TypePair , IEquivalentComparer > ( ) ;
2020
21- private static readonly IDictionary < IConfigurationProvider , IList < IGeneratePropertyMaps > > GeneratePropertyMapsDictionary = new Dictionary < IConfigurationProvider , IList < IGeneratePropertyMaps > > ( ) ;
21+ private static readonly ConcurrentDictionary < IConfigurationProvider , IList < IGeneratePropertyMaps > > GeneratePropertyMapsDictionary = new ConcurrentDictionary < IConfigurationProvider , IList < IGeneratePropertyMaps > > ( ) ;
2222 private static IList < IGeneratePropertyMaps > _generatePropertyMapsCache = new List < IGeneratePropertyMaps > ( ) ;
2323
2424 public static void AddCollectionMappers ( this IMapperConfigurationExpression cfg )
@@ -41,10 +41,10 @@ private static void InsertBefore<TObjectMapper>(this IMapperConfigurationExpress
4141 foreach ( var configurationObjectMapper in adds )
4242 configurationObjectMapper . ConfigurationProvider = c ;
4343
44- EquivalentExpressionDictionary . Add ( c , _equalityComparisonCache ) ;
44+ EquivalentExpressionDictionary . AddOrUpdate ( c , _equalityComparisonCache , ( type , old ) => _equalityComparisonCache ) ;
4545 _equalityComparisonCache = new ConcurrentDictionary < TypePair , IEquivalentComparer > ( ) ;
4646
47- GeneratePropertyMapsDictionary . Add ( c , _generatePropertyMapsCache ) ;
47+ GeneratePropertyMapsDictionary . AddOrUpdate ( c , _generatePropertyMapsCache , ( type , old ) => _generatePropertyMapsCache ) ;
4848 _generatePropertyMapsCache = new List < IGeneratePropertyMaps > ( ) ;
4949 } ) ;
5050 }
@@ -54,7 +54,7 @@ internal static IEquivalentComparer GetEquivalentExpression(this IConfigurationO
5454 var typeMap = mapper . ConfigurationProvider . ResolveTypeMap ( sourceType , destinationType ) ;
5555 return typeMap == null ? null : GetEquivalentExpression ( mapper . ConfigurationProvider , typeMap ) ;
5656 }
57-
57+
5858 internal static IEquivalentComparer GetEquivalentExpression ( IConfigurationProvider configurationProvider , TypeMap typeMap )
5959 {
6060 return EquivalentExpressionDictionary [ configurationProvider ] . GetOrAdd ( typeMap . Types ,
@@ -70,8 +70,8 @@ internal static IEquivalentComparer GetEquivalentExpression(IConfigurationProvid
7070 /// <param name="mappingExpression">Base Mapping Expression</param>
7171 /// <param name="EquivalentExpression">Equivalent Expression between <typeparamref name="TSource"/> and <typeparamref name="TDestination"/></param>
7272 /// <returns></returns>
73- public static IMappingExpression < TSource , TDestination > EqualityComparison < TSource , TDestination > ( this IMappingExpression < TSource , TDestination > mappingExpression , Expression < Func < TSource , TDestination , bool > > EquivalentExpression )
74- where TSource : class
73+ public static IMappingExpression < TSource , TDestination > EqualityComparison < TSource , TDestination > ( this IMappingExpression < TSource , TDestination > mappingExpression , Expression < Func < TSource , TDestination , bool > > EquivalentExpression )
74+ where TSource : class
7575 where TDestination : class
7676 {
7777 var typePair = new TypePair ( typeof ( TSource ) , typeof ( TDestination ) ) ;
@@ -91,7 +91,7 @@ public static void SetGeneratePropertyMaps(this IMapperConfigurationExpression c
9191 {
9292 _generatePropertyMapsCache . Add ( generatePropertyMaps ) ;
9393 }
94-
94+
9595 private static IEquivalentComparer CreateEquivalentExpression ( this IEnumerable < PropertyMap > propertyMaps )
9696 {
9797 if ( ! propertyMaps . Any ( ) || propertyMaps . Any ( pm => pm . DestinationProperty . GetMemberType ( ) != pm . SourceMember . GetMemberType ( ) ) )
0 commit comments