diff --git a/src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs b/src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs index 8ea35b8043..4493e8a41b 100644 --- a/src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs +++ b/src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs @@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Builder /// public static class HealthCheckEndpointRouteBuilderExtensions { + private const string DefaultDisplayName = "Health checks"; + /// /// Adds a health checks endpoint to the with the specified template. /// @@ -29,7 +31,7 @@ namespace Microsoft.AspNetCore.Builder throw new ArgumentNullException(nameof(builder)); } - return MapHealthChecksCore(builder, pattern, null); + return MapHealthChecksCore(builder, pattern, null, DefaultDisplayName); } /// @@ -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) + /// + /// Adds a health checks endpoint to the with the specified template, options and display name. + /// + /// The to add the health checks endpoint to. + /// The URL pattern of the health checks endpoint. + /// A used to configure the health checks. + /// The display name for the endpoint. + /// A convention builder for the health checks endpoint. + 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(); @@ -65,7 +99,7 @@ namespace Microsoft.AspNetCore.Builder .UseMiddleware(args) .Build(); - return builder.Map(pattern, "Health checks", pipeline); + return builder.Map(pattern, displayName, pipeline); } } }