ASP.NET Core 2 Unable to resolve service for type Microsoft EntityFrameworkCore DbContext

StudentService expects DbContext but the container does not know how to resolve it based on your current startup.

You would need to either explicitly add the context to the service collection

Startup

services.AddScoped<DbContext, SchoolContext>();
services.AddScoped<IStudentService, StudentService>();

Or update the StudentService constructor to explicitly expect a type the container knows how to resolve.

StudentService

public StudentService(SchoolContext context)
    : base(context)
{ 
    //...
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)