首页 > 解决方案 > 尝试激活“AspNetCoreRateLimit.IpRateLimitMiddleware”时无法解析“AspNetCoreRateLimit.IProcessingStrategy”类型的服务

问题描述

我使用了 AspNetCoreRateLimit Version="4.0.1" 包,但出现以下异常: Unable to resolve service for type 'AspNetCoreRateLimit.IProcessingStrategy' while trying to activate 'AspNetCoreRateLimit.IpRateLimitMiddleware' 但是当我使用包 AspNetCoreRateLimit Version=" 3.2.2" 有效。虽然 Version="4.0.1" 是最新的稳定版本,但我无法使用它。如果我继续使用 Version="3.2.2",以后会出现什么样的错误?

标签: asp.net-web-apiversionnuget-packagerate-limitingasp.net-core-5.0

解决方案


根据 AspNetCoreRateLimit 的作者,您必须在 Startup.cs 中添加以下代码行

services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();

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


推荐阅读