0
votes

I've created a project with .NET CORE 3.1 and SQL Server database.

I have implemented a CRUD with scaffolding for my class Model "Route", but when I go to https://localhost:44381/Routes appears an arror:

An unhandled exception occurred while processing the request. InvalidOperationException: Unable to resolve service for type 'Agalber.Hostel.Backoffice.Models.Agalber_Des2Context' while attempting to activate 'Agalber.Hostel.Backoffice.Controllers.RoutesController'. Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired).

1
The error means you haven't registered Agalber_Des2Context with the DI container. Add an AddDbContext< Agalber_Des2Context>(...) call in ConfigureServices. - Panagiotis Kanavos
Thank you, i have added: services.AddScoped(typeof(Agalber_Des2Context)); And works fine. - Sergio Cores Acha

1 Answers

0
votes

In order to resolve this issue is nedded to add the following line in the ConfigureServices methos of the Startup.cs file:

services.AddScoped(typeof("Name of class DbContext"));

Thank you @Panagiotis Kanavos