Skip to content

Commit

Permalink
AddTypeActivatedCheck coverage (#15582)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored Nov 15, 2019
1 parent 1b86849 commit 306780e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion aspnetcore/host-and-deploy/health-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Learn how to set up health checks for ASP.NET Core infrastructure,
monikerRange: '>= aspnetcore-2.2'
ms.author: riande
ms.custom: mvc
ms.date: 11/03/2019
ms.date: 11/13/2019
uid: host-and-deploy/health-checks
---
# Health checks in ASP.NET Core
Expand Down Expand Up @@ -144,6 +144,40 @@ services.AddHealthChecks()
HealthCheckResult.Healthy("Example is OK!"), tags: new[] { "example" });
```

Call <xref:Microsoft.Extensions.DependencyInjection.HealthChecksBuilderAddCheckExtensions.AddTypeActivatedCheck*> to pass arugments to a health check implementation. In the following example, `TestHealthCheckWithArgs` accepts an integer and a string for use when <xref:Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck.CheckHealthAsync*> is called:

```csharp
private class TestHealthCheckWithArgs : IHealthCheck
{
public TestHealthCheckWithArgs(int i, string s)
{
I = i;
S = s;
}

public int I { get; set; }

public string S { get; set; }

public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context,
CancellationToken cancellationToken = default)
{
...
}
}
```

`TestHealthCheckWithArgs` is registered by calling `AddTypeActivatedCheck` with the integer and string passed to the implementation:

```csharp
services.AddHealthChecks()
.AddTypeActivatedCheck<TestHealthCheckWithArgs>(
"test",
failureStatus: HealthStatus.Degraded,
tags: new[] { "example" },
args: new object[] { 5, "string" });
```

## Use Health Checks Routing

In `Startup.Configure`, call `MapHealthChecks` on the endpoint builder with the endpoint URL or relative path:
Expand Down

0 comments on commit 306780e

Please sign in to comment.