AspNetCoreRateLimit
AspNetCoreRateLimit copied to clipboard
Unable to resolve service for type 'Microsoft.Extensions.Caching.Distributed.IDistributedCache'
AspNetCoreRateLimit.Redis is not working.
just adding (and some config) var redisOptions = ConfigurationOptions.Parse("dc"); services.AddSingleton<IConnectionMultiplexer>(provider => ConnectionMultiplexer.Connect(redisOptions)); services.AddRedisRateLimiting(); is not enough:
'Unable to resolve service for type 'Microsoft.Extensions.Caching.Distributed.IDistributedCache' while attempting to activate 'AspNetCoreRateLimit.DistributedCacheClientPolicyStore'.'
Hi! Have you found any way to fix this?
Worked for me in .NET 6 API -
I installed the following nuget packages -
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="AspNetCoreRateLimit.Redis" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.15" />
In program.cs -
var redisConnectionString = builder.Configuration.GetConnectionString("Redis");
builder.Services.AddStackExchangeRedisCache(o =>
{
o.Configuration = redisConnectionString;
o.InstanceName = "AspNetCoreRateLimiting:";
});
builder.Services.AddSingleton<IConnectionMultiplexer>(provider => ConnectionMultiplexer.Connect(redisConnectionString));
builder.Services.AddRedisRateLimiting();