Skip to content

Commit 1fed78a

Browse files
authored
Only add MethodInfo to route handler endpoints (#44021)
1 parent 5b84d4c commit 1fed78a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/Http/Routing/src/RouteEndpointDataSource.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,13 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
168168
{
169169
DisplayName = displayName,
170170
ApplicationServices = _applicationServices,
171-
Metadata = { handler.Method },
172171
};
173172

173+
if (isRouteHandler)
174+
{
175+
builder.Metadata.Add(handler.Method);
176+
}
177+
174178
if (entry.HttpMethods is not null)
175179
{
176180
builder.Metadata.Add(new HttpMethodMetadata(entry.HttpMethods));

src/Http/Routing/test/UnitTests/Builder/RequestDelegateEndpointRouteBuilderExtensionsTest.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,9 @@ public void MapEndpoint_AttributesCollectedAsMetadata()
190190
// Assert
191191
var endpointBuilder1 = GetRouteEndpointBuilder(builder);
192192
Assert.Equal("/", endpointBuilder1.RoutePattern.RawText);
193-
Assert.Equal(3, endpointBuilder1.Metadata.Count);
194-
Assert.Equal(((RequestDelegate)Handle).Method, endpointBuilder1.Metadata[0]);
195-
Assert.IsType<Attribute1>(endpointBuilder1.Metadata[1]);
196-
Assert.IsType<Attribute2>(endpointBuilder1.Metadata[2]);
193+
Assert.Equal(2, endpointBuilder1.Metadata.Count);
194+
Assert.IsType<Attribute1>(endpointBuilder1.Metadata[0]);
195+
Assert.IsType<Attribute2>(endpointBuilder1.Metadata[1]);
197196
}
198197

199198
[Fact]
@@ -228,11 +227,10 @@ public void MapEndpoint_PrecedenceOfMetadata_BuilderMetadataReturned()
228227

229228
// As with the Delegate Map method overloads for route handlers, the attributes on the RequestDelegate
230229
// can override the HttpMethodMetadata. Extension methods could already do this.
231-
Assert.Equal(4, endpoint.Metadata.Count);
232-
Assert.Equal(((RequestDelegate)HandleHttpMetdata).Method, endpoint.Metadata[0]);
233-
Assert.Equal("METHOD", GetMethod(endpoint.Metadata[1]));
234-
Assert.Equal("ATTRIBUTE", GetMethod(endpoint.Metadata[2]));
235-
Assert.Equal("BUILDER", GetMethod(endpoint.Metadata[3]));
230+
Assert.Equal(3, endpoint.Metadata.Count);
231+
Assert.Equal("METHOD", GetMethod(endpoint.Metadata[0]));
232+
Assert.Equal("ATTRIBUTE", GetMethod(endpoint.Metadata[1]));
233+
Assert.Equal("BUILDER", GetMethod(endpoint.Metadata[2]));
236234

237235
Assert.Equal("BUILDER", endpoint.Metadata.GetMetadata<IHttpMethodMetadata>()?.HttpMethods.Single());
238236

0 commit comments

Comments
 (0)