Closed huanbd closed 1 year ago
seems like the call to services.AddMemoryCache()
in the AddCaching
method here:
https://github.com/fullstackhero/dotnet-webapi-boilerplate/blob/370dc7bb7a5c84af53ea37cdffa109060b07807e/src/Infrastructure/Caching/Startup.cs#L36
will have to go outside of the if/else block...
Thank you that solve the exception, How about the next line services.AddTransient<ICacheService, LocalCacheService>(); should be moved as well or its ok inside the else?
Regards
No, if you enable redis, ICacheService is the RedisCacheService, otherwise it's the LocalCacheService... this lets you seamlessly switch between local and remote cache... The local cache is using IMemoryCache internally, but apparently IMemoryCache is also used by some other components (outside of the LocalCacheService). That's why that one needs to be registered always.
If you only want always local memory cache (irregardless of using reddis) it's best to use IMemoryCache itself in stead of ICacheService.
@fretje can i work on this?
Describe the bug When I change cache settings to use Distributed cache Redis. It cause error initialize Localization
Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Routing.Matching.DfaMatcherBuilder Lifetime: Transient ImplementationType: Microsoft.AspNetCore.Routing.Matching.DfaMatcherBuilder': Unable to resolve service for type 'Microsoft.Extensions.Caching.Memory.IMemoryCache' while attempting to activate 'OrchardCore.Localization.LocalizationManager'.)
To Reproduce Steps to reproduce the behavior:
{ "CacheSettings": { "UseDistributedCache": true, "PreferRedis": true, "RedisURL": "localhost:6379" } }