From 306780e73d39afb935d6da32a42dccd1026c1543 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Thu, 14 Nov 2019 20:40:45 -0600 Subject: [PATCH] AddTypeActivatedCheck coverage (#15582) --- aspnetcore/host-and-deploy/health-checks.md | 36 ++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/aspnetcore/host-and-deploy/health-checks.md b/aspnetcore/host-and-deploy/health-checks.md index 0df4f71259..9964aed80f 100644 --- a/aspnetcore/host-and-deploy/health-checks.md +++ b/aspnetcore/host-and-deploy/health-checks.md @@ -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 to pass arugments to a health check implementation. In the following example, `TestHealthCheckWithArgs` accepts an integer and a string for use when 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 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( + "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: