Browse Source

Use TryAdd for adding entitycache

pull/14055/head
Halil İbrahim Kalkan 4 years ago
parent
commit
91fcbd8b3e
  1. 16
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs

16
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Volo.Abp.Domain.Entities.Caching; namespace Volo.Abp.Domain.Entities.Caching;
@ -8,11 +9,12 @@ public static class EntityCacheServiceCollectionExtensions
this IServiceCollection services) this IServiceCollection services)
where TEntity : Entity<TKey> where TEntity : Entity<TKey>
{ {
return services services
.AddTransient< .TryAddTransient<
IEntityCache<TEntity, TKey>, IEntityCache<TEntity, TKey>,
EntityCacheWithoutCacheItem<TEntity, TKey> EntityCacheWithoutCacheItem<TEntity, TKey>
>(); >();
return services;
} }
public static IServiceCollection AddEntityCache<TEntity, TEntityCacheItem, TKey>( public static IServiceCollection AddEntityCache<TEntity, TEntityCacheItem, TKey>(
@ -20,11 +22,12 @@ public static class EntityCacheServiceCollectionExtensions
where TEntity : Entity<TKey> where TEntity : Entity<TKey>
where TEntityCacheItem : class where TEntityCacheItem : class
{ {
return services services
.AddTransient< .TryAddTransient<
IEntityCache<TEntityCacheItem, TKey>, IEntityCache<TEntityCacheItem, TKey>,
EntityCacheWithObjectMapper<TEntity, TEntityCacheItem, TKey> EntityCacheWithObjectMapper<TEntity, TEntityCacheItem, TKey>
>(); >();
return services;
} }
public static IServiceCollection AddEntityCache<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>( public static IServiceCollection AddEntityCache<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>(
@ -32,10 +35,11 @@ public static class EntityCacheServiceCollectionExtensions
where TEntity : Entity<TKey> where TEntity : Entity<TKey>
where TEntityCacheItem : class where TEntityCacheItem : class
{ {
return services services
.AddTransient< .TryAddTransient<
IEntityCache<TEntityCacheItem, TKey>, IEntityCache<TEntityCacheItem, TKey>,
EntityCacheWithObjectMapperContext<TObjectMapperContext, TEntity, TEntityCacheItem, TKey> EntityCacheWithObjectMapperContext<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>
>(); >();
return services;
} }
} }
Loading…
Cancel
Save