ServiceDefaults.HealthChecks 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ServiceDefaults.HealthChecks --version 1.2.0
                    
NuGet\Install-Package ServiceDefaults.HealthChecks -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ServiceDefaults.HealthChecks" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ServiceDefaults.HealthChecks" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="ServiceDefaults.HealthChecks" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ServiceDefaults.HealthChecks --version 1.2.0
                    
#r "nuget: ServiceDefaults.HealthChecks, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ServiceDefaults.HealthChecks@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ServiceDefaults.HealthChecks&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=ServiceDefaults.HealthChecks&version=1.2.0
                    
Install as a Cake Tool

ServiceDefaults.HealthChecks

Production-ready health check infrastructure for ASP.NET Core services with separate liveness, readiness, and startup endpoints - designed for Kubernetes deployments.

Installation

dotnet add package ServiceDefaults.HealthChecks

Quick Start

var builder = WebApplication.CreateBuilder(args);

// Add health check infrastructure
builder.AddHealthCheckDefaults();

// Add PostgreSQL readiness check
builder.AddPostgresReadinessCheck(
    builder.Configuration.GetConnectionString("Postgres")!);

var app = builder.Build();

// Run migrations BEFORE marking ready
using (var scope = app.Services.CreateScope())
{
    var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
    await db.Database.MigrateAsync();
}

// Mark app as ready AFTER migrations complete
app.MarkAsReady();

// Map health endpoints
app.MapHealthCheckEndpoints();

app.Run();

Health Check Endpoints

Endpoint Purpose Checks Kubernetes Probe
/health/live Is the app running? Self check only livenessProbe
/health/ready Can it handle traffic? DB + Startup state readinessProbe

Why Separate Endpoints?

Probe Checks Fails when Effect
Liveness App loop only App is wedged Container restarted
Readiness DB + migrations Traffic would fail Removed from LB

Critical Rule: Liveness should NEVER check external dependencies like databases. A database hiccup shouldn't restart your containers.

Kubernetes Configuration

livenessProbe:
  httpGet:
    path: /health/live
    port: 8080
  periodSeconds: 10
  timeoutSeconds: 1
  failureThreshold: 3

readinessProbe:
  httpGet:
    path: /health/ready
    port: 8080
  periodSeconds: 5
  timeoutSeconds: 2
  failureThreshold: 1

startupProbe:
  httpGet:
    path: /health/live
    port: 8080
  failureThreshold: 30
  periodSeconds: 5

API Reference

Builder Extensions

// Add core health checks (liveness + startup state)
builder.AddHealthCheckDefaults();

// Add PostgreSQL readiness check
builder.AddPostgresReadinessCheck(connectionString, name: "postgres", timeout: TimeSpan.FromSeconds(2));

App Extensions

// Map endpoints (defaults: /health/live, /health/ready)
app.MapHealthCheckEndpoints();

// Custom paths
app.MapHealthCheckEndpoints(
    liveEndpoint: "/healthz",
    readyEndpoint: "/ready");

// Mark ready after initialization
app.MarkAsReady();

// Get startup state for manual control
var state = app.GetStartupState();
state.MarkReady();
state.MarkNotReady(); // For graceful shutdown

StartupState

The StartupState class tracks whether your app has completed initialization:

// Injected via DI
public class MyService
{
    private readonly StartupState _startupState;

    public MyService(StartupState startupState)
    {
        _startupState = startupState;
    }

    public bool IsReady => _startupState.IsReady;
}

Response Format

Health endpoints return JSON:

{
  "status": "Healthy",
  "totalDuration": 12.5,
  "checks": [
    {
      "name": "postgres",
      "status": "Healthy",
      "duration": 10.2,
      "description": null,
      "exception": null
    },
    {
      "name": "startup",
      "status": "Healthy",
      "duration": 0.1,
      "description": "Application startup complete",
      "exception": null
    }
  ]
}

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.1 309 3/7/2026
1.3.0 1,258 1/11/2026
1.2.4 106 1/10/2026
1.2.3 106 1/10/2026
1.2.2 97 1/10/2026
1.2.1 109 1/10/2026
1.2.0 109 1/10/2026
1.1.0 101 1/10/2026
1.0.1 98 1/10/2026