Update the health check endpoint route builder extensions to make the endpoint display name configurable. (#8359)

This commit is contained in:
Chris Baudin 2019-03-08 17:25:57 -08:00 committed by Ryan Nowak
parent 96764d27eb
commit 484978fe59
1 changed files with 38 additions and 4 deletions

View File

@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Builder
/// </summary>
public static class HealthCheckEndpointRouteBuilderExtensions
{
private const string DefaultDisplayName = "Health checks";
/// <summary>
/// Adds a health checks endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template.
/// </summary>
@ -29,7 +31,7 @@ namespace Microsoft.AspNetCore.Builder
throw new ArgumentNullException(nameof(builder));
}
return MapHealthChecksCore(builder, pattern, null);
return MapHealthChecksCore(builder, pattern, null, DefaultDisplayName);
}
/// <summary>
@ -54,10 +56,42 @@ namespace Microsoft.AspNetCore.Builder
throw new ArgumentNullException(nameof(options));
}
return MapHealthChecksCore(builder, pattern, options);
return MapHealthChecksCore(builder, pattern, options, DefaultDisplayName);
}
private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuilder builder, string pattern, HealthCheckOptions options)
/// <summary>
/// Adds a health checks endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template, options and display name.
/// </summary>
/// <param name="builder">The <see cref="IEndpointRouteBuilder"/> to add the health checks endpoint to.</param>
/// <param name="pattern">The URL pattern of the health checks endpoint.</param>
/// <param name="options">A <see cref="HealthCheckOptions"/> used to configure the health checks.</param>
/// <param name="displayName">The display name for the endpoint.</param>
/// <returns>A convention builder for the health checks endpoint.</returns>
public static IEndpointConventionBuilder MapHealthChecks(
this IEndpointRouteBuilder builder,
string pattern,
HealthCheckOptions options,
string displayName)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
if (string.IsNullOrEmpty(displayName))
{
throw new ArgumentException("A valid non-empty display name must be provided.", nameof(displayName));
}
return MapHealthChecksCore(builder, pattern, options, displayName);
}
private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuilder builder, string pattern, HealthCheckOptions options, string displayName)
{
var args = options != null ? new[] { Options.Create(options) } : Array.Empty<object>();
@ -65,7 +99,7 @@ namespace Microsoft.AspNetCore.Builder
.UseMiddleware<HealthCheckMiddleware>(args)
.Build();
return builder.Map(pattern, "Health checks", pipeline);
return builder.Map(pattern, displayName, pipeline);
}
}
}