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