StackExchange.Redis.Extensions icon indicating copy to clipboard operation
StackExchange.Redis.Extensions copied to clipboard

Exception on DI

Open pablotdv opened this issue 4 years ago • 1 comments

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

pablotdv avatar May 12 '21 00:05 pablotdv

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"

imperugo avatar Jun 25 '21 12:06 imperugo