How do you add pre-built health checks for common external dependencies like SQL Server, Redis, or a URL endpoint, using the community AspNetCore.Diagnostics.HealthChecks packages?
Short answer
The community-maintained AspNetCore.Diagnostics.HealthChecks repository provides numerous ready-made health check packages (AspNetCore.HealthChecks.SqlServer, .Redis, .Uri, etc.) for common dependencies, avoiding the need to hand-write IHealthCheck implementations for standard…
Advertisement
AModel answer
The community-maintained AspNetCore.Diagnostics.HealthChecks repository provides numerous ready-made health check packages (AspNetCore.HealthChecks.SqlServer, .Redis, .Uri, etc.) for common dependencies, avoiding the need to hand-write IHealthCheck implementations for standard infrastructure -- each is registered via a fluent extension method on the IHealthChecksBuilder, typically just needing a connection string or URL.
// After: dotnet add package AspNetCore.HealthChecks.SqlServer
// dotnet add package AspNetCore.HealthChecks.Redis
builder.Services.AddHealthChecks()
.AddSqlServer(builder.Configuration.GetConnectionString("Default"), name: "sql-server")
.AddRedis(builder.Configuration.GetConnectionString("Redis"), name: "redis")
.AddUrlGroup(new Uri("https://api.partner.com/health"), name: "partner-api");Real-world example
A team adds SQL Server, Redis, and an external partner API health check to their /health endpoint entirely through community NuGet packages and one-line registrations, avoiding weeks of effort hand-writing and testing custom connectivity-checking logic for each dependency type.
Likely follow-ups
- How do you evaluate whether a community health check package is trustworthy and well-maintained before depending on it in production?
- How would you write a custom check for a dependency type not covered by any existing community package?
Related topics