尝试激活 'AspNetCoreRateLimit.IpRateLimitMiddleware' 时无法解析类型 'AspNetCoreRateLimit.IProcessingStrategy' 的服务

Unable to resolve service for type 'AspNetCoreRateLimit.IProcessingStrategy' while attempting to activate 'AspNetCoreRateLimit.IpRateLimitMiddleware'

我使用了 AspNetCoreRateLimit Version="4.0.1" 包,但出现以下异常:尝试激活 'AspNetCoreRateLimit.IpRateLimitMiddleware' 时无法解析类型 'AspNetCoreRateLimit.IProcessingStrategy' 的服务,但是当我使用包 AspNetCoreRateLimit Version="3.2.2" 它有效。虽然 Version="4.0.1" 是最新的稳定版本,但我无法使用它。如果我继续使用 Version="3.2.2",我以后会遇到什么样的错误?

根据 AspNetCoreRateLimit 的作者,您必须在 Startup.cs

中添加以下代码行
services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();

他们似乎不再注册默认的 IProcessingStrategy。看这里:https://github.com/stefanprodan/AspNetCoreRateLimit/issues/236#issuecomment-883311511