[英]Migrating the asp.net core 3.1 to .net 6 error
我正在将其中一个项目从 .net 核心 3.1 迁移到 .net 6。其中一个项目未构建并引发此错误。
ConfigureServicesExtensions.cs(62, 22): [CS1061] 'IServiceCollection' 不包含'Decorate' 的定义,并且找不到接受'IServiceCollection' 类型的第一个参数的可访问扩展方法'Decorate'(您是否缺少使用指令还是程序集引用?)
请参阅下面的代码示例,其中从 .net 3.1 升级到 6.0 后失败
private static void RegisterCommandHandlers(IServiceCollection serviceCollection)
{
//Scruptor package : https://andrewlock.net/using-scrutor-to-automatically-register-your-services-with-the-asp-net-core-di-container/
serviceCollection.Scan(scan => scan.FromAssemblyOf<ICommand>()
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<>))
.Where(_ => !_.IsGenericType))
.AsImplementedInterfaces()
.WithTransientLifetime());
serviceCollection.Decorate(typeof(ICommandHandler<>), typeof(CommandHandlerLoggingDecorator<>));
}
如果你的包是最新的,你可以试试这个:
清理并重建您的解决方案。
重启VS
与其说是答案,不如说是猜测——AFAIK build DI 从未公开过任何Decorate
方法,我知道的方法来自Scrutor
库。 检查是否安装了这个库。
UPD
基于添加的代码 - 只需安装Scrutor
nuget 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.