AddScoped Cause System.AggregateException: 'Einige Dienste können nicht konstruiert werden (Fehler bei der Validierung d

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: AddScoped Cause System.AggregateException: 'Einige Dienste können nicht konstruiert werden (Fehler bei der Validierung d

by Anonymous » 03 Apr 2025, 08:37

Ich untersuche, wie man API in .NET 8 schreibe. Wie löste ich es? Todoapidb.data.todoItemService ':

Diener nicht in der Lage, den Typ' Microsoft.EntityFrameworkcore.dbset`1 [toDoapidb.models.todoItem] '

während zu aktivieren, um' todoapidb.data. /todoapidb.data zu aktivieren ''. /> < /blockquote>

Code: Select all

Program.cs
:

Code: Select all

builder.Services.AddScoped();
< /code>
ITodoItemsService.cs
:

Code: Select all

public interface ITodoItemsService
{
List? GetAbunch(string[] myAnimals);
}
< /code>
TodoItemsService.cs
:
public class TodoItemsService: ITodoItemsService
{
private readonly DbSet _todoItems;

public TodoItemsService(DbSet todoItems)
{
_todoItems = todoItems;
}

List? ITodoItemsService.GetAbunch(string[] myAnimals)
{
var animals = _todoItems.Where(i => myAnimals.Contains(i.Name))
.ToList();

return animals;
}
}
< /code>
GitHub code of the API application.
Screenshot of the error in Visual Studio:
Image

Top