Skip to content

Commit 74df1e3

Browse files
committed
Support setting endpoints on group names to resolve #34541
1 parent e6c4335 commit 74df1e3

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/Http/Routing/src/Builder/RoutingEndpointConventionBuilderExtensions.cs

+13
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,18 @@ public static TBuilder WithName<TBuilder>(this TBuilder builder, string endpoint
131131
builder.WithMetadata(new EndpointNameMetadata(endpointName));
132132
return builder;
133133
}
134+
135+
/// <summary>
136+
/// Sets the <see cref="EndpointGroupNameMetadata"/> for all endpoints produced
137+
/// on the target <see cref="IEndpointConventionBuilder"/>.
138+
/// </summary>
139+
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
140+
/// <param name="endpointGroupName">The endpoint group name.</param>
141+
/// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns>
142+
public static TBuilder WithGroupName<TBuilder>(this TBuilder builder, string endpointGroupName) where TBuilder : IEndpointConventionBuilder
143+
{
144+
builder.WithMetadata(new EndpointGroupNameMetadata(endpointGroupName));
145+
return builder;
146+
}
134147
}
135148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using Microsoft.AspNetCore.Http;
6+
7+
namespace Microsoft.AspNetCore.Routing
8+
{
9+
/// <summary>
10+
/// Specifies an endpoint group name in <see cref="Endpoint.Metadata"/>.
11+
/// </summary>
12+
public class EndpointGroupNameMetadata : IEndpointGroupNameMetadata
13+
{
14+
/// <summary>
15+
/// Creates a new instance of <see cref="EndpointGroupNameMetadata"/> with the provided endpoint name.
16+
/// </summary>
17+
/// <param name="endpointGroupName">The endpoint name.</param>
18+
public EndpointGroupNameMetadata(string endpointGroupName)
19+
{
20+
if (endpointGroupName == null)
21+
{
22+
throw new ArgumentNullException(nameof(endpointGroupName));
23+
}
24+
25+
EndpointGroupName = endpointGroupName;
26+
}
27+
28+
/// <summary>
29+
/// Gets the endpoint name.
30+
/// </summary>
31+
public string EndpointGroupName { get; }
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.AspNetCore.Http;
5+
6+
namespace Microsoft.AspNetCore.Routing
7+
{
8+
/// <summary>
9+
/// Defines a contract use to specify an endpoint group name in <see cref="Endpoint.Metadata"/>.
10+
/// </summary>
11+
public interface IEndpointGroupNameMetadata
12+
{
13+
/// <summary>
14+
/// Gets the endpoint group name.
15+
/// </summary>
16+
string EndpointGroupName { get; }
17+
}
18+
}

0 commit comments

Comments
 (0)