小编paw*_*eto的帖子

AggregateException:某些服务无法构建

我有一个 .NET 5.0 项目,一切正常 - 构建、执行、正常工作 - 直到 4 月 10 日。

现在我在注册服务时遇到很多错误。

Unhandled exception. System.AggregateException: Some services are not able to be constructed 
(Error while validating the service descriptor 'ServiceType: AService.DataAccess.MyDbContext 
Lifetime: Scoped ImplementationType: AService.DataAccess.MyDbContext': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbSet`1[AService.Domain.Entities.B.B]' while 
attempting to activate 'AService.DataAccess.MyDbContext'.) (Error while validating the 
service descriptor 'ServiceType: 
MediatR.IRequestHandler`2[AService.Api.Queries.B.GetAllQuery, 
System.Collections.Generic.IEnumerable`1[AService.Api.Queries.B.Dtos.BDto]] 
Lifetime: Transient ImplementationType: 
AService.Queries.B.GetAllQueryHandler': Unable to resolve service for type 
'Microsoft.EntityFrameworkCore.DbSet`1[AService.Domain.Entities.B.B]' while 
attempting to activate 'AService.DataAccess.MyDbContext'.)
Run Code Online (Sandbox Code Playgroud)

我简短地说 - 每个存储库、每个服务、需要注册的所有内容都注册如下Startup.cs

public void …
Run Code Online (Sandbox Code Playgroud)

.net c# dependency-injection entity-framework-core asp.net-core

5
推荐指数
1
解决办法
2万
查看次数