@@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Builder
14
14
/// </summary>
15
15
public static class HealthCheckEndpointRouteBuilderExtensions
16
16
{
17
+ private const string DefaultDisplayName = "Health checks" ;
18
+
17
19
/// <summary>
18
20
/// Adds a health checks endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template.
19
21
/// </summary>
@@ -29,7 +31,7 @@ public static IEndpointConventionBuilder MapHealthChecks(
29
31
throw new ArgumentNullException ( nameof ( builder ) ) ;
30
32
}
31
33
32
- return MapHealthChecksCore ( builder , pattern , null ) ;
34
+ return MapHealthChecksCore ( builder , pattern , null , DefaultDisplayName ) ;
33
35
}
34
36
35
37
/// <summary>
@@ -54,18 +56,50 @@ public static IEndpointConventionBuilder MapHealthChecks(
54
56
throw new ArgumentNullException ( nameof ( options ) ) ;
55
57
}
56
58
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 ) ;
58
92
}
59
93
60
- private static IEndpointConventionBuilder MapHealthChecksCore ( IEndpointRouteBuilder builder , string pattern , HealthCheckOptions options )
94
+ private static IEndpointConventionBuilder MapHealthChecksCore ( IEndpointRouteBuilder builder , string pattern , HealthCheckOptions options , string displayName )
61
95
{
62
96
var args = options != null ? new [ ] { Options . Create ( options ) } : Array . Empty < object > ( ) ;
63
97
64
98
var pipeline = builder . CreateApplicationBuilder ( )
65
99
. UseMiddleware < HealthCheckMiddleware > ( args )
66
100
. Build ( ) ;
67
101
68
- return builder . Map ( pattern , "Health checks" , pipeline ) ;
102
+ return builder . Map ( pattern , displayName , pipeline ) ;
69
103
}
70
104
}
71
105
}
0 commit comments