You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If I have (directly or indirectly) already registered an IMemoryCache instance with the DI container, then services.AddLazyCache() fails with the following exception:
System.Security.VerificationException: Method Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Singleton: type argument 'Microsoft.Extensions.Caching.Memory.MemoryCache' violates the constraint of type parameter 'TImplementation'.
Expected behavior
Ideally, AddLazyCache would to try to use any existing global IMemoryCache instance if one already exists, rather than expecting that it is always the first library to register its IMemoryCache singleton. I realize that this puts the burden of managing that IMemoryCache on the client, but that would be a given anyways.
Framework and Platform
OS: Windows 10
Framework: .NET 6
LazyCache Version: LazyCache.AspNetCore 2.4.0
Additional context
I ran into this because the NSwag library/CLI injects an IMemoryCache during its OpenAPI model generation process before my Startup.cs is ever invoked. Here is the commit of the workaround that I had to use: CareTogether/CareTogetherCMS@076200d
The text was updated successfully, but these errors were encountered:
Describe the bug
If I have (directly or indirectly) already registered an
IMemoryCache
instance with the DI container, thenservices.AddLazyCache()
fails with the following exception:To Reproduce
Expected behavior
Ideally,
AddLazyCache
would to try to use any existing globalIMemoryCache
instance if one already exists, rather than expecting that it is always the first library to register itsIMemoryCache
singleton. I realize that this puts the burden of managing thatIMemoryCache
on the client, but that would be a given anyways.Framework and Platform
Additional context
I ran into this because the NSwag library/CLI injects an
IMemoryCache
during its OpenAPI model generation process before my Startup.cs is ever invoked. Here is the commit of the workaround that I had to use:CareTogether/CareTogetherCMS@076200d
The text was updated successfully, but these errors were encountered: