Please Ensure DbContext is registered in the Dependency Injection container inStartup.cs or Program.cs file.
If it's not registered use below code.
services.AddDbContext<YourDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));