C#C
C#2y ago
Spaxter

DbContextFactory check for valid connection on app startup

I have a .NET app where I'm currently using EF Core's DbContextFactory with Postgres. However I noticed that no matter what host I set in my connection string the app starts normally and no errors are thrown. Is it possible to validate the connection at startup?

builder.Services.AddDbContextFactory<DataContext>(options => 
{
    options.UseNpgsql(postgresOptions.ConnectionString);
}
Was this page helpful?