diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs index 6bded3c401..f426e9adcb 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Caching/EntityCacheServiceCollectionExtensions.cs +++ b/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 { - return services - .AddTransient< + services + .TryAddTransient< IEntityCache, EntityCacheWithoutCacheItem >(); + return services; } public static IServiceCollection AddEntityCache( @@ -20,11 +22,12 @@ public static class EntityCacheServiceCollectionExtensions where TEntity : Entity where TEntityCacheItem : class { - return services - .AddTransient< + services + .TryAddTransient< IEntityCache, EntityCacheWithObjectMapper >(); + return services; } public static IServiceCollection AddEntityCache( @@ -32,10 +35,11 @@ public static class EntityCacheServiceCollectionExtensions where TEntity : Entity where TEntityCacheItem : class { - return services - .AddTransient< + services + .TryAddTransient< IEntityCache, EntityCacheWithObjectMapperContext >(); + return services; } } \ No newline at end of file