I'm trying to scaffold identity on UI SuplementShop.WEB.Mvc solution in Visual Studio 2022.
I'm new to ASP.NET so I hope somebody can help me :)
Open repository on GitHub: (version before scaffolding)
https://github.com/7LinesOfCode/SuplementShopWEB.MVC
Thanks in advance for every response :)
I want to make Login and Register scaffold, with data context
"Context (Suplement.WEB.Mvc.Infrastructure)". After that step my app can't compile anymore.
Observations: after making scaffolding (as I said above) output in the console look like this:
After scaffolding if I try to debug my app, I get an exception in
var app = builder.Build()
List of errors:
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType:
SuplementShopWEB.MVC.Application.Interfaces.IOrderService Lifetime: Transient ImplementationType:
SuplementShopWEB.MVC.Application.Services.OrderService': Unable to resolve service for type 'SuplementShopWEB.MVC.Infrastructure.Context' while attempting to activate 'SuplementShopWEB.MVC.Infrastructure.Repositories.OrderRepository'.) (Error while validating the service descriptor 'ServiceType: SuplementShopWEB.MVC.Application.Interfaces.ICustomerService Lifetime: Transient ImplementationType: SuplementShopWEB.MVC.Application.Services.CustomerService': Unable to resolve service for type 'SuplementShopWEB.MVC.Infrastructure.Context' while attempting to activate 'SuplementShopWEB.MVC.Infrastructure.Repositories.CustomerRepository'.) (Error while validating the service descriptor 'ServiceType: SuplementShopWEB.MVC.Application.Interfaces.IItemService Lifetime: Transient ImplementationType: SuplementShopWEB.MVC.Application.Services.ItemService': Unable to resolve service for type 'SuplementShopWEB.MVC.Infrastructure.Context' while attempting to activate 'SuplementShopWEB.MVC.Infrastructure.Repositories.ItemRepository'.) (Error while validating the service descriptor 'ServiceType: SuplementShopWEB.MVC.Domain.Interface.IOrderRepository Lifetime: Transient ImplementationType: SuplementShopWEB.MVC.Infrastructure.Repositories.OrderRepository': Unable to resolve service for type 'SuplementShopWEB.MVC.Infrastructure.Context' while attempting to activate 'SuplementShopWEB.MVC.Infrastructure.Repositories.OrderRepository'.) (Error while validating the service descriptor 'ServiceType: SuplementShopWEB.MVC.Domain.Interface.ICustomerRepository Lifetime: Transient ImplementationType: SuplementShopWEB.MVC.Infrastructure.Repositories.CustomerRepository': Unable to resolve service for type 'SuplementShopWEB.MVC.Infrastructure.Context' while attempting to activate 'SuplementShopWEB.MVC.Infrastructure.Repositories.CustomerRepository'.) (Error while validating the service descriptor 'ServiceType: SuplementShopWEB.MVC.Domain.Interface.IItemRepository Lifetime: Transient ImplementationType: SuplementShopWEB.MVC.Infrastructure.Repositories.ItemRepository': Unable to resolve service for type 'SuplementShopWEB.MVC.Infrastructure.Context' while attempting to activate 'SuplementShopWEB.MVC.Infrastructure.Repositories.ItemRepository'.)'
After that I can find a new connection string in appsettings.json.
Before scaffolding action, application had no errors and was working fine.
After I cloned your project from github, I find the error and fix them, You can follow these steps.
First change your
dbcontextclass name, give it an unique name likeMyApplicationDbcontextinstead of just calledContext, Then add related page in Scuffolding identity according to thisdbcontextThen click add button to add these identity pages.
Now you need to add-migration and update-database, First set your MVC project as the startup project, Then in Package Manager Console, set Infrastructure project as default project.
Finally use
to migration and create database.
Update: