IRedisConnectionPoolManager is not registered
Hi everyone, thanks for the amazing work in this project! I would like to migrate from version 7 to version 8 and I am facing some issues. It could be simply reproduced by using the current sample included in this project at samples/StackExchange.Redis.Samples.Web.Mvc:
- Checked out the latest code of this project
- I have opened the project in VS Code
- Switching to folder /samples/StackExchange.Redis.Samples.Web.Mvc in a terminal and use "dotnet build" and "dotnet run" to start the sample
- Browse to https://localhost:5001/
The constructor of the HomeController which will be called then looks like this:
public HomeController(IRedisDatabase redisDatabase, IRedisConnectionPoolManager pool)
Basically the problem is that the IRedisConnectionPoolManager is no longer properly registered via IoC so if you want to let the .NET framework create an instance of it it will fail:
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Unable to resolve service for type 'StackExchange.Redis.Extensions.Core.Abstractions.IRedisConnectionPoolManager' while attempting to activate 'StackExchange.Redis.Samples.Web.Mvc.Controllers.HomeController'.
The problem might be introduced because the method "AddStackExchangeRedisExtensions" has been changed in V8. In previous version the "IRedisConnectionPoolManager" was registered as a singleton which is no longer the case:
Before:
services.AddSingleton<IRedisCacheClient, RedisCacheClient>();
services.AddSingleton<IRedisCacheConnectionPoolManager, RedisCacheConnectionPoolManager>();
services.AddSingleton<ISerializer, T>();
services.AddSingleton((provider) => provider.GetRequiredService<IRedisCacheClient>().GetDbFromConfiguration());
services.AddSingleton(redisConfigurationFactory);
Now:
services.AddSingleton<IRedisClientFactory, RedisClientFactory>();
services.AddSingleton<ISerializer, T>();
services.AddSingleton((provider) => provider
.GetRequiredService<IRedisClientFactory>()
.GetDefaultRedisClient());
services.AddSingleton((provider) => provider
.GetRequiredService<IRedisClientFactory>()
.GetDefaultRedisClient()
.GetDefaultDatabase());
services.AddSingleton(redisConfigurationFactory);
Please give advice how to proceed, by either updating "AddStackExchangeRedisExtensions" or to update the sample project to show what needs to be done instead.
Thank you.
Hi @sprudel79 I'm working on the documentation "how to upgrate to v8". In the meanwhile you can take a look here
https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/src/aspnet/StackExchange.Redis.Extensions.AspNetCore/Extensions/IServiceCollectionExtensions.cs#L57-L69
Thanks @imperugo , I appreciate your reply and the efforts in the migration documentation. The selected source code is identical with the one I've mentioned in my previous post. As I understood the example is simply not yet migrated and the IRedisConnectionPoolManager interface should not be used anymore in any constructor concerning dependency injection. In my project I have paid attention to that already and I can use the library v8 without any issues.
Hi, I am facing issue while migrating from version 7.2.1 to v 8.0.5. I am not able to find RedisCacheConnectionPoolManager , and RedishCacheClient in this version. Is the documentation on how to upgrade to v8 available? Could you please redirect me to the same?
I Have problem with this below dependency <PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="6.3.5" /> <PackageReference Include="StackExchange.Redis.Extensions.MsgPack" Version="6.3.5" /> <PackageReference Include="StackExchange.Redis.Extensions.Core" Version="6.3.5" /> when your this dependency update .net 6.0 and above dependency update to version 9.1 we are missing namespacess like, services.AddSingleton<IRedisCacheClient, RedisCacheClient>(); services.AddSingleton<IRedisCacheConnectionPoolManager, RedisCacheConnectionPoolManager>(); services.AddSingleton<ISerializer, MsgPackObjectSerializer>(); can give correct solution for me
RedisCacheClient has been renamed to RedisClient and RedisCacheConnectionPoolManager to RedisConnectionPoolManager similarly Cache word has been removed from interfaces as well.
Any solution for this IRedisConnectionPoolManager" was registered as a singleton which is no longer the case
Hi @lavanyaputtaswamy
there is no reason why IRedisConnectionPoolManager shouldn't be registered as singleton. I use it as singleton since years without issue.
If you change it as transient for example, means that you will recreate the connections every time and this is super expensive.
see here the connection pool
https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/src/core/StackExchange.Redis.Extensions.Core/Implementations/RedisConnectionPoolManager.cs#L46C46-L46C57