Ошибка: невозможно создать «DbContext» типа «». Исключение «Невозможно разрешить службу для типа Microsoft.EntityFrameworkCore.DbContextOptions`1[HealthCheck.Console.Context.SystemHealthContext]» при попытке активировать «HealthCheck.Console.Context.SystemHealthContext». был выброшен при попытке создать экземпляр. Сведения о различных шаблонах, поддерживаемых во время разработки, см. на странице https://go.microsoft.com/fwlink/?linkid=851728
Вот мой DbContext< /code> класс
Код: Выделить всё
public class SystemHealthContext : DbContext
{
public SystemHealthContext(DbContextOptions options) : base(options) { }
public DbSet ServerMasterInfo { get; set; }
}
Код: Выделить всё
var configuration = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
var services = new ServiceCollection();
var connectionString = configuration.GetConnectionString("DbConnection");
services.AddDbContext(options =>
options.UseSqlServer(connectionString));
services.AddTransient();
var serviceProvider = services.BuildServiceProvider();
var systemHealthCheck = serviceProvider.GetRequiredService();
Заранее спасибо
Подробнее здесь: https://stackoverflow.com/questions/791 ... solve-serv