Skip to content

Instantly share code, notes, and snippets.

Created December 25, 2018 13:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using System.Threading;
using System.Threading.Tasks;
public class DatabaseHealthCheck : IHealthCheck
private readonly DbContext dbContext;
public DatabaseHealthCheck(DbContext context)
this.dbContext = context;
public async Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context,
CancellationToken cancellationToken = default(CancellationToken))
var canConnectToDatabase =
await dbContext.Database.CanConnectAsync();
if (canConnectToDatabase)
return HealthCheckResult.Healthy();
return HealthCheckResult.Unhealthy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment