File tree Expand file tree Collapse file tree 3 files changed +8
-2
lines changed
src/CleanArchitecture.Extensions.Caching Expand file tree Collapse file tree 3 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 44using CleanArchitecture . Extensions . Caching . Options ;
55using CleanArchitecture . Extensions . Caching . Serialization ;
66using Microsoft . Extensions . Caching . Distributed ;
7+ using Microsoft . Extensions . DependencyInjection ;
78using Microsoft . Extensions . Logging ;
89using Microsoft . Extensions . Options ;
910
@@ -47,6 +48,7 @@ public DistributedCacheAdapter(
4748 /// <param name="options">Caching options.</param>
4849 /// <param name="timeProvider">Time provider used for timestamps.</param>
4950 /// <param name="logger">Logger.</param>
51+ [ ActivatorUtilitiesConstructor ]
5052 public DistributedCacheAdapter (
5153 IDistributedCache distributedCache ,
5254 IEnumerable < ICacheSerializer > serializers ,
Original file line number Diff line number Diff line change 44using CleanArchitecture . Extensions . Caching . Options ;
55using CleanArchitecture . Extensions . Caching . Serialization ;
66using Microsoft . Extensions . Caching . Memory ;
7+ using Microsoft . Extensions . DependencyInjection ;
78using Microsoft . Extensions . Logging ;
89using Microsoft . Extensions . Options ;
910
@@ -47,6 +48,7 @@ public MemoryCacheAdapter(
4748 /// <param name="timeProvider">Time provider used for timestamps.</param>
4849 /// <param name="options">Caching options.</param>
4950 /// <param name="logger">Logger.</param>
51+ [ ActivatorUtilitiesConstructor ]
5052 public MemoryCacheAdapter (
5153 IMemoryCache memoryCache ,
5254 IEnumerable < ICacheSerializer > serializers ,
Original file line number Diff line number Diff line change @@ -47,8 +47,10 @@ public static IServiceCollection AddCleanArchitectureCaching(
4747 services . TryAddSingleton < ICacheKeyFactory , DefaultCacheKeyFactory > ( ) ;
4848 // Call AddCleanArchitectureMultitenancyCaching to bind cache scopes to tenant context.
4949 services . TryAddScoped < ICacheScope , DefaultCacheScope > ( ) ;
50- services . TryAddSingleton < ICache , MemoryCacheAdapter > ( ) ;
51- services . TryAddSingleton < DistributedCacheAdapter > ( ) ;
50+ services . TryAddSingleton < ICache > ( sp =>
51+ ActivatorUtilities . CreateInstance < MemoryCacheAdapter > ( sp , sp . GetServices < ICacheSerializer > ( ) ) ) ;
52+ services . TryAddSingleton < DistributedCacheAdapter > ( sp =>
53+ ActivatorUtilities . CreateInstance < DistributedCacheAdapter > ( sp , sp . GetServices < ICacheSerializer > ( ) ) ) ;
5254
5355 return services ;
5456 }
You can’t perform that action at this time.
0 commit comments