AddTypeActivatedCheck coverage (#15582)

pull/15700/head
Luke Latham 2019-11-14 20:40:45 -06:00 committed by GitHub
parent 1b86849aaa
commit 306780e73d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 1 deletions

View File

@ -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
@ -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: