ASP.NET Core health check for Microsoft Dataverse that verifies connectivity by executing a WhoAmI request against the registered ServiceClient.
- One-line health check registration via
AddDataverseHealthCheck()onIHealthChecksBuilder - Keyed client support via
AddKeyedDataverseHealthCheck(serviceKey)for multi-environment scenarios - Returns
UserId,OrganizationId, andBusinessUnitIdin the health check result data - Uses
context.Registration.FailureStatusso consumers control whether failure isUnhealthyorDegraded - Works independently of how
ServiceClientwas registered — pairs naturally withBauerApps.Dataverse.Extensions.DependencyInjection
Install the package from NuGet:
dotnet add package BauerApps.Dataverse.Extensions.HealthChecksRegister the health check in Program.cs alongside your ServiceClient:
// Register ServiceClient (e.g. via the companion DI package)
builder.Services.AddDataverseClient(options =>
{
options.OrganizationUrl = new Uri("https://my-org.crm4.dynamics.com");
});
// Add health check
builder.Services.AddHealthChecks()
.AddDataverseHealthCheck();Map the health check endpoint:
app.MapHealthChecks("/health");On success the result contains:
{
"status": "Healthy",
"description": "Dataverse connection is healthy.",
"data": {
"UserId": "a1b2c3d4-...",
"OrganizationId": "e5f6g7h8-...",
"BusinessUnitId": "i9j0k1l2-..."
}
}On failure the result includes the exception and reports the configured failureStatus (Unhealthy by default).
| Parameter | Default | Description |
|---|---|---|
name |
"dataverse" |
Name shown in health reports and used for filtering. |
failureStatus |
Unhealthy |
Status to report on failure. Pass Degraded for non-critical environments. |
tags |
null |
Tags for filtering (e.g. "ready", "live"). |
timeout |
null |
Per-registration timeout. Defaults to the global health check timeout. |
builder.Services.AddHealthChecks()
.AddDataverseHealthCheck(failureStatus: HealthStatus.Degraded);builder.Services.AddHealthChecks()
.AddDataverseHealthCheck(tags: ["ready"]);
app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("ready")
});When using keyed ServiceClient registrations, use AddKeyedDataverseHealthCheck:
builder.Services.AddDataverseClient("source", options =>
options.OrganizationUrl = new Uri("https://source.crm4.dynamics.com"));
builder.Services.AddDataverseClient("target", options =>
options.OrganizationUrl = new Uri("https://target.crm4.dynamics.com"));
builder.Services.AddHealthChecks()
.AddKeyedDataverseHealthCheck("source", name: "dataverse-source", tags: ["ready"])
.AddKeyedDataverseHealthCheck("target", name: "dataverse-target", tags: ["ready"]);The name defaults to the serviceKey when not provided, so each keyed check appears separately in health reports.