依赖注入时出错:Cannot consume scoped service 'xxx' from singleton 'yyy'

错误:

System.AggregateException:“Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: WebApplication9.Models.BgServerTest': Cannot consume scoped service 'WebApplication9.Models.Imywork' from singleton 'Microsoft.Extensions.Hosting.IHostedService'.)”

InvalidOperationException: Cannot consume scoped service 'WebApplication9.Models.Imywork' from singleton 'Microsoft.Extensions.Hosting.IHostedService'.

 

解决办法 :

 

posted @ 2021-08-06 21:25  lunawzh  阅读(4774)  评论(0编辑  收藏  举报