StackExchange.Redis.Extensions
StackExchange.Redis.Extensions copied to clipboard
Exception on DI
When I tried to add the dependencies as a singleton, I had the following error on services.AddSingleton((provider) => provider.GetRequiredService<IRedisCacheClient>().GetDbFromConfiguration());:
System.InvalidOperationException: 'Cannot resolve scoped service 'StackExchange.Redis.Extensions.Core.Abstractions.IRedisCacheClient' from root provider.'
To Reproduce Add dependencies as a singleton
services.AddSingleton<IRedisCacheClient, RedisCacheClient>();
services.AddSingleton<IRedisCacheConnectionPoolManager, RedisCacheConnectionPoolManager>();
services.AddSingleton<ISerializer, SystemTextJsonSerializer>();
services.AddSingleton((provider) => provider.GetRequiredService<IRedisCacheClient>().GetDbFromConfiguration());
services.AddSingleton(conf);
Desktop:
- OS: Windows
- Runtime version: 5.0.203
- Version: 7.0
Hi, there is a specific package for that
https://github.com/imperugo/StackExchange.Redis.Extensions/tree/master/src/aspnet/StackExchange.Redis.Extensions.AspNetCore
Here https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/samples/StackExchange.Redis.Samples.Web.Mvc/Startup.cs#L42 and example on "how to use it"