ServiceDefaults.HealthChecks 2.0.0

dotnet add package ServiceDefaults.HealthChecks --version 2.0.0
                    
NuGet\Install-Package ServiceDefaults.HealthChecks -Version 2.0.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="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ServiceDefaults.HealthChecks" Version="2.0.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 2.0.0
                    
#r "nuget: ServiceDefaults.HealthChecks, 2.0.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@2.0.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=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ServiceDefaults.HealthChecks&version=2.0.0
                    
Install as a Cake Tool

ServiceDefaults.HealthChecks

2.0.0 is a breaking change. The PostgreSQL readiness check moved to Dloizides.HealthChecks.Npgsql; this package now has no third-party dependencies. See CHANGELOG.md.

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/start Has startup finished? Startup state only startupProbe
/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/start
    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 net10.0 is compatible.  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.
  • net10.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on ServiceDefaults.HealthChecks:

Package Downloads
Bff.AspNetCore

Reusable Backend-For-Frontend engine for ASP.NET Core. Terminates auth server-side: holds OIDC tokens in a Redis-backed session, hands the browser only an opaque httpOnly cookie, and forwards Bearer tokens to downstream services via YARP. Provider-agnostic — targets Keycloak (default, realm-scoped) or a generic OpenIddict provider (/connect/*), selectable per app. Server-side ROPC (Keycloak) or authorization-code + PKCE, silent refresh with a per-session SETNX lock, and CSRF protection. A per-app BFF becomes a ~20-line Program.cs.

Dloizides.ServiceDefaults

Aspire-style service defaults for ASP.NET Core: OpenTelemetry (logging/metrics/tracing) wiring, HTTP resilience + service discovery, standard health-check registration (via ServiceDefaults.HealthChecks), and the platform endpoint map (anonymous /health/live|start|ready Kubernetes probes plus an ACME HTTP-01 no-op). Extracted from ~8 services that had each hand-copied the ServiceDefaults/Extensions.cs; normalizes the PostgressConnection connection-string typo by resolving both the correct (PostgresConnection) and legacy-typo keys.

Dloizides.HealthChecks.Npgsql

PostgreSQL readiness probe for ServiceDefaults.HealthChecks. Adds AddPostgresReadinessCheck to the shared readiness tag. Kept out of the core package so services without a database take no Npgsql dependency.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 214 9/8/2026
1.3.1 1,203 3/7/2026
1.3.0 1,290 1/11/2026
1.2.4 137 1/10/2026
1.2.3 140 1/10/2026
1.2.2 132 1/10/2026
1.2.1 140 1/10/2026
1.2.0 144 1/10/2026
1.1.0 135 1/10/2026
1.0.1 131 1/10/2026