Skip to content

Commit 484978f

Browse files
CBaudrynowak
authored andcommitted
Update the health check endpoint route builder extensions to make the endpoint display name configurable. (#8359)
1 parent 96764d2 commit 484978f

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/Middleware/HealthChecks/src/Builder/HealthCheckEndpointRouteBuilderExtensions.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Builder
1414
/// </summary>
1515
public static class HealthCheckEndpointRouteBuilderExtensions
1616
{
17+
private const string DefaultDisplayName = "Health checks";
18+
1719
/// <summary>
1820
/// Adds a health checks endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template.
1921
/// </summary>
@@ -29,7 +31,7 @@ public static IEndpointConventionBuilder MapHealthChecks(
2931
throw new ArgumentNullException(nameof(builder));
3032
}
3133

32-
return MapHealthChecksCore(builder, pattern, null);
34+
return MapHealthChecksCore(builder, pattern, null, DefaultDisplayName);
3335
}
3436

3537
/// <summary>
@@ -54,18 +56,50 @@ public static IEndpointConventionBuilder MapHealthChecks(
5456
throw new ArgumentNullException(nameof(options));
5557
}
5658

57-
return MapHealthChecksCore(builder, pattern, options);
59+
return MapHealthChecksCore(builder, pattern, options, DefaultDisplayName);
60+
}
61+
62+
/// <summary>
63+
/// Adds a health checks endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template, options and display name.
64+
/// </summary>
65+
/// <param name="builder">The <see cref="IEndpointRouteBuilder"/> to add the health checks endpoint to.</param>
66+
/// <param name="pattern">The URL pattern of the health checks endpoint.</param>
67+
/// <param name="options">A <see cref="HealthCheckOptions"/> used to configure the health checks.</param>
68+
/// <param name="displayName">The display name for the endpoint.</param>
69+
/// <returns>A convention builder for the health checks endpoint.</returns>
70+
public static IEndpointConventionBuilder MapHealthChecks(
71+
this IEndpointRouteBuilder builder,
72+
string pattern,
73+
HealthCheckOptions options,
74+
string displayName)
75+
{
76+
if (builder == null)
77+
{
78+
throw new ArgumentNullException(nameof(builder));
79+
}
80+
81+
if (options == null)
82+
{
83+
throw new ArgumentNullException(nameof(options));
84+
}
85+
86+
if (string.IsNullOrEmpty(displayName))
87+
{
88+
throw new ArgumentException("A valid non-empty display name must be provided.", nameof(displayName));
89+
}
90+
91+
return MapHealthChecksCore(builder, pattern, options, displayName);
5892
}
5993

60-
private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuilder builder, string pattern, HealthCheckOptions options)
94+
private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuilder builder, string pattern, HealthCheckOptions options, string displayName)
6195
{
6296
var args = options != null ? new[] { Options.Create(options) } : Array.Empty<object>();
6397

6498
var pipeline = builder.CreateApplicationBuilder()
6599
.UseMiddleware<HealthCheckMiddleware>(args)
66100
.Build();
67101

68-
return builder.Map(pattern, "Health checks", pipeline);
102+
return builder.Map(pattern, displayName, pipeline);
69103
}
70104
}
71105
}

0 commit comments

Comments
 (0)