.NET 7 MVC 应用程序中的脚手架身份问题

问题描述 投票:0回答:1

我正在尝试在 Viusal Studio 2022 中的 UI SuplementShop.WEB.Mvc 解决方案上破坏身份。

我是 ASP.NET 新手,所以我希望有人可以帮助我:)

在 GitHub 上打开存储库: (脚手架之前的版本) https://github.com/7LinesOfCode/SuplementShopWEB.MVC

预先感谢您的每一个回复:)

我想让登录和注册脚手架,带有数据上下文 “上下文(补充.WEB.Mvc.基础设施)”。在那一步之后,我的应用程序无法再编译。

观察:-制作脚手架后(正如我上面所说)输出控制台如下所示:enter image description here

-在搭建脚手架之后,如果我尝试调试我的应用程序,我可以在“var app = builder.Build()”中获得豁免enter image description here 错误列表:

System.AggregateException:“某些服务无法构建(验证服务描述符时出错”ServiceType:SuplementShopWEB.MVC.Application.Interfaces.IOrderService 生命周期:瞬态实现类型:SuplementShopWEB.MVC.Application.Services.OrderService”:无法在尝试激活“SuplementShopWEB.MVC.Infrastruct.Repositories.OrderRepository”时解析类型“SuplementShopWEB.MVC.Infrastruct.Context”的服务。)(验证服务描述符“ServiceType:SuplementShopWEB.MVC.Application.Interfaces.ICustomerService”时出错生命周期:瞬态实现类型:SuplementShopWEB.MVC.Application.Services.CustomerService':尝试激活'SuplementShopWEB.MVC.Infrastruct.Repositories.CustomerRepository'时无法解析类型'SuplementShopWEB.MVC.Infrastruct.Context'的服务。)(错误验证服务描述符“ServiceType:SuplementShopWEB.MVC.Application.Interfaces.IItemService 生命周期:瞬态实现类型:SuplementShopWEB.MVC.Application.Services.ItemService”时:尝试时无法解析类型“SuplementShopWEB.MVC.Infrastruct.Context”的服务激活“SuplementShopWEB.MVC.Infrastruct.Repositories.ItemRepository”。)(验证服务描述符“ServiceType:SuplementShopWEB.MVC.Domain.Interface.IOrderRepository”时出错:瞬态实现类型:SuplementShopWEB.MVC.Infrastruct.Repositories.OrderRepository“:尝试激活“SuplementShopWEB.MVC.Infrastruct.Repositories.OrderRepository”时,无法解析类型“SuplementShopWEB.MVC.Infrastruct.Context”的服务。)(验证服务描述符“ServiceType:SuplementShopWEB.MVC.Domain.Interface”时出错。 ICustomerRepository 生命周期:瞬态实现类型:SuplementShopWEB.MVC.Infrastruct.Repositories.CustomerRepository':尝试激活“SuplementShopWEB.MVC.Infrastruct.Repositories.CustomerRepository”时无法解析类型“SuplementShopWEB.MVC.Infrastruct.Context”的服务。)(验证服务描述符“ServiceType:SuplementShopWEB.MVC.Domain.Interface.IItemRepository 生命周期:瞬态实现类型:SuplementShopWEB.MVC.Infrastruct.Repositories.ItemRepository”时出错:无法解析类型“SuplementShopWEB.MVC.Infrastruct.Context”的服务尝试激活“SuplementShopWEB.MVC.Infrastruct.Repositories.ItemRepository”。)'

-之后我可以在 appsettings.json 中找到新的连接字符串

-在脚手架操作应用程序没有错误并且运行良好之前。

c# .net asp.net-core-mvc scaffolding asp.net-mvc-scaffolding
1个回答
0
投票

我从github克隆了你的项目后,我发现了错误并修复了它们,你可以按照以下步骤操作。

首先更改您的

dbcontext
类名称,给它一个唯一的名称,例如
MyApplicationDbcontext
,而不是仅仅称为
Context
,然后根据此
dbcontext

在Scuffolding标识中添加相关页面

然后单击添加按钮添加这些身份页面。

现在您需要添加迁移和更新数据库,首先将您的 MVC 项目设置为启动项目,然后在 Package Manager Console 中将基础设施项目设置为默认项目。

终于可以使用了

add-migration MyMigration -Context MyApplicationDbcontext

update-database -Context MyApplicationDbcontext

迁移并创建数据库。

© www.soinside.com 2019 - 2024. All rights reserved.