Example #1
0
 public static IMappingOperationOptions UseEntityCache <TKey, TEntity>(
     this IMappingOperationOptions options,
     IEntityCacheAccessor <TKey, TEntity> entityCache)
     where TEntity : class
 {
     EntityCacheResolutionContextHelper.Add(options.Items, entityCache);
     return(options);
 }
        private IEntityCacheAccessor <TSourceMember, TEntity> GetCacheAccessor(ResolutionContext resolutionContext)
        {
            if (!_cacheAccessors.TryGetValue(resolutionContext, out var cacheAccessor))
            {
                cacheAccessor = EntityCacheResolutionContextHelper.Get <TSourceMember, TEntity>(resolutionContext.Items);

                if (cacheAccessor is null)
                {
                    throw new AutoMapperMappingException(
                              $"{nameof(ResolutionContext)} does not contain '{nameof(IEntityCacheAccessor<TSourceMember, TEntity>)}' entity cache type.");
                }

                _cacheAccessors.Add(resolutionContext, cacheAccessor);
            }

            return(cacheAccessor);
        }