Skip to content

Commit bb2b157

Browse files
committed
Renames
- Also add MethodInfo to all endpoint metadata in RouteEndpointDataSource
1 parent 6594c90 commit bb2b157

10 files changed

+52
-55
lines changed

src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Microsoft.AspNetCore.Http.ProblemDetailsOptions.ProblemDetailsOptions() -> void
3838
*REMOVED*Microsoft.AspNetCore.Mvc.ProblemDetails.Title.set -> void
3939
*REMOVED*Microsoft.AspNetCore.Mvc.ProblemDetails.Type.get -> string?
4040
*REMOVED*Microsoft.AspNetCore.Mvc.ProblemDetails.Type.set -> void
41+
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.RouteHandlerFilterFactories.get -> System.Collections.Generic.IList<System.Func<Microsoft.AspNetCore.Http.EndpointFilterFactoryContext!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!>!>?
42+
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.RouteHandlerFilterFactories.init -> void
4143
Microsoft.AspNetCore.Mvc.ProblemDetails (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
4244
Microsoft.AspNetCore.Mvc.ProblemDetails.Detail.get -> string? (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
4345
Microsoft.AspNetCore.Mvc.ProblemDetails.Detail.set -> void (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
@@ -52,8 +54,6 @@ Microsoft.AspNetCore.Mvc.ProblemDetails.Title.set -> void (forwarded, contained
5254
Microsoft.AspNetCore.Mvc.ProblemDetails.Type.get -> string? (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
5355
Microsoft.AspNetCore.Mvc.ProblemDetails.Type.set -> void (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
5456
Microsoft.Extensions.DependencyInjection.ProblemDetailsServiceCollectionExtensions
55-
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.EndpointFilterFactories.get -> System.Collections.Generic.IReadOnlyList<System.Func<Microsoft.AspNetCore.Http.EndpointFilterFactoryContext!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!>!>?
56-
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.EndpointFilterFactories.init -> void
5757
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.EndpointMetadata.get -> System.Collections.Generic.IList<object!>?
5858
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.EndpointMetadata.init -> void
5959
Microsoft.Extensions.DependencyInjection.HttpJsonServiceExtensions

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private static FactoryContext CreateFactoryContext(RequestDelegateFactoryOptions
208208
RouteParameters = options?.RouteParameterNames?.ToList(),
209209
ThrowOnBadRequest = options?.ThrowOnBadRequest ?? false,
210210
DisableInferredFromBody = options?.DisableInferBodyFromParameters ?? false,
211-
FilterFactories = options?.EndpointFilterFactories?.ToList(),
211+
FilterFactories = options?.RouteHandlerFilterFactories?.ToList(),
212212
Metadata = options?.EndpointMetadata ?? new List<object>(),
213213
};
214214
}

src/Http/Http.Extensions/src/RequestDelegateFactoryOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public sealed class RequestDelegateFactoryOptions
3636
/// <summary>
3737
/// The list of filters that must run in the pipeline for a given route handler.
3838
/// </summary>
39-
public IReadOnlyList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>? EndpointFilterFactories { get; init; }
39+
public IList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>? RouteHandlerFilterFactories { get; init; }
4040

4141
/// <summary>
4242
/// The mutable initial endpoint metadata to add as part of the creation of the <see cref="RequestDelegateResult.RequestDelegate"/>. In most cases,

src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,7 +4889,7 @@ string HelloName(string name)
48894889
// Act
48904890
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
48914891
{
4892-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
4892+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
48934893
{
48944894
(routeHandlerContext, next) => async (context) =>
48954895
{
@@ -4921,7 +4921,7 @@ public async Task RequestDelegateFactory_InvokesFilters_OnDelegateWithTarget()
49214921
// Act
49224922
var factoryResult = RequestDelegateFactory.Create((string name) => $"Hello, {name}!", new RequestDelegateFactoryOptions()
49234923
{
4924-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
4924+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
49254925
{
49264926
(routeHandlerContext, next) => async (context) =>
49274927
{
@@ -4963,7 +4963,7 @@ public async Task RequestDelegateFactory_InvokesFilters_OnMethodInfoWithNullTarg
49634963
// Act
49644964
var factoryResult = RequestDelegateFactory.Create(methodInfo!, null, new RequestDelegateFactoryOptions()
49654965
{
4966-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
4966+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
49674967
{
49684968
(routeHandlerContext, next) => async (context) =>
49694969
{
@@ -5006,7 +5006,7 @@ public async Task RequestDelegateFactory_InvokesFilters_OnMethodInfoWithProvided
50065006
};
50075007
var factoryResult = RequestDelegateFactory.Create(methodInfo!, targetFactory, new RequestDelegateFactoryOptions()
50085008
{
5009-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5009+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
50105010
{
50115011
(routeHandlerContext, next) => async (context) =>
50125012
{
@@ -5043,7 +5043,7 @@ string HelloName(string name)
50435043
// Act
50445044
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
50455045
{
5046-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>() {
5046+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>() {
50475047
(routeHandlerContext, next) => async (context) =>
50485048
{
50495049
if (context.HttpContext.Response.StatusCode == 400)
@@ -5089,7 +5089,7 @@ string HelloName(string name, int age)
50895089
// Act
50905090
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
50915091
{
5092-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5092+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
50935093
{
50945094
(routeHandlerContext, next) => async (context) =>
50955095
{
@@ -5137,7 +5137,7 @@ string HelloName(string name)
51375137
// Act
51385138
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
51395139
{
5140-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5140+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
51415141
{
51425142
(routeHandlerContext, next) =>
51435143
{
@@ -5192,7 +5192,7 @@ string HelloName(IFormFileCollection formFiles)
51925192
// Act
51935193
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
51945194
{
5195-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5195+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
51965196
{
51975197
(routeHandlerContext, next) =>
51985198
{
@@ -5243,7 +5243,7 @@ string PrintTodo(Todo todo)
52435243
// Act
52445244
var factoryResult = RequestDelegateFactory.Create(PrintTodo, new RequestDelegateFactoryOptions()
52455245
{
5246-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5246+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
52475247
{
52485248
(routeHandlerContext, next) => async (context) =>
52495249
{
@@ -5284,7 +5284,7 @@ string HelloName(string name)
52845284
// Act
52855285
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
52865286
{
5287-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5287+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
52885288
{
52895289
(routeHandlerContext, next) => async (context) =>
52905290
{
@@ -5327,7 +5327,7 @@ string HelloName(string name)
53275327
// Act
53285328
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
53295329
{
5330-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5330+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
53315331
{
53325332
(routeHandlerContext, next) => async (context) =>
53335333
{
@@ -5396,7 +5396,7 @@ public async Task CanInvokeFilter_OnTaskOfTReturningHandler(Delegate @delegate)
53965396
// Act
53975397
var factoryResult = RequestDelegateFactory.Create(@delegate, new RequestDelegateFactoryOptions()
53985398
{
5399-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5399+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
54005400
{
54015401
(routeHandlerContext, next) => async (context) =>
54025402
{
@@ -5454,7 +5454,7 @@ public async Task CanInvokeFilter_OnValueTaskOfTReturningHandler(Delegate @deleg
54545454
// Act
54555455
var factoryResult = RequestDelegateFactory.Create(@delegate, new RequestDelegateFactoryOptions()
54565456
{
5457-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5457+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
54585458
{
54595459
(routeHandlerContext, next) => async (context) =>
54605460
{
@@ -5519,7 +5519,7 @@ public async Task CanInvokeFilter_OnVoidReturningHandler(Delegate @delegate)
55195519
// Act
55205520
var factoryResult = RequestDelegateFactory.Create(@delegate, new RequestDelegateFactoryOptions()
55215521
{
5522-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5522+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
55235523
{
55245524
(routeHandlerContext, next) => async (context) =>
55255525
{
@@ -5553,7 +5553,7 @@ async Task HandlerWithTaskAwait(HttpContext c)
55535553
// Act
55545554
var factoryResult = RequestDelegateFactory.Create(HandlerWithTaskAwait, new RequestDelegateFactoryOptions()
55555555
{
5556-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5556+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
55575557
{
55585558
(routeHandlerContext, next) => async (context) =>
55595559
{
@@ -5620,7 +5620,7 @@ public async Task CanInvokeFilter_OnHandlerReturningTasksOfStruct(Delegate @dele
56205620
// Act
56215621
var factoryResult = RequestDelegateFactory.Create(@delegate, new RequestDelegateFactoryOptions()
56225622
{
5623-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5623+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
56245624
{
56255625
(routeHandlerContext, next) => async (context) =>
56265626
{
@@ -5656,7 +5656,7 @@ string HelloName(int? one, string? two, int? three, string? four, int? five, boo
56565656
// Act
56575657
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
56585658
{
5659-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5659+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
56605660
{
56615661
(routeHandlerContext, next) => async (context) =>
56625662
{
@@ -5687,7 +5687,7 @@ string HelloName()
56875687
// Act
56885688
var factoryResult = RequestDelegateFactory.Create(HelloName, new RequestDelegateFactoryOptions()
56895689
{
5690-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
5690+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
56915691
{
56925692
(routeHandlerContext, next) => async (context) =>
56935693
{
@@ -6081,7 +6081,7 @@ public void Create_ReturnsSameRequestDelegatePassedIn_IfNotModifiedByFilters()
60816081

60826082
RequestDelegateFactoryOptions options = new()
60836083
{
6084-
EndpointFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
6084+
RouteHandlerFilterFactories = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>()
60856085
{
60866086
(routeHandlerContext, next) =>
60876087
{

src/Http/Routing/src/Builder/EndpointFilterExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ public static TBuilder AddEndpointFilter<TBuilder>(this TBuilder builder, Func<E
117117
return;
118118
}
119119

120-
routeEndpointBuilder.EndpointFilterFactories ??= new();
121-
routeEndpointBuilder.EndpointFilterFactories.Add(filterFactory);
120+
routeEndpointBuilder.RouteHandlerFilterFactories.Add(filterFactory);
122121
});
123122

124123
return builder;

src/Http/Routing/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#nullable enable
22
Microsoft.AspNetCore.Http.EndpointFilterExtensions
33
Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.Dispose() -> void
4+
Microsoft.AspNetCore.Routing.RouteEndpointBuilder.RouteHandlerFilterFactories.get -> System.Collections.Generic.IList<System.Func<Microsoft.AspNetCore.Http.EndpointFilterFactoryContext!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!>!>!
45
Microsoft.AspNetCore.Routing.RouteGroupBuilder
56
Microsoft.AspNetCore.Routing.RouteGroupContext
67
Microsoft.AspNetCore.Routing.RouteGroupContext.ApplicationServices.get -> System.IServiceProvider!

src/Http/Routing/src/RouteEndpointBuilder.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ namespace Microsoft.AspNetCore.Routing;
1212
/// </summary>
1313
public sealed class RouteEndpointBuilder : EndpointBuilder
1414
{
15-
// TODO: Make this public as a gettable IReadOnlyList<Func<RouteHandlerContext, EndpointFilterDelegate, EndpointFilterDelegate>>.
16-
// AddEndpointFilter will still be the only way to mutate this list.
17-
internal List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>? EndpointFilterFactories { get; set; }
18-
1915
/// <summary>
2016
/// Gets or sets the <see cref="RoutePattern"/> associated with this endpoint.
2117
/// </summary>
2218
public RoutePattern RoutePattern { get; set; }
2319

20+
/// <summary>
21+
/// Gets the collection of route handler filter factories associated with this endpoint.
22+
/// </summary>
23+
public IList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>> RouteHandlerFilterFactories { get; }
24+
= new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>();
25+
2426
/// <summary>
2527
/// Gets or sets the order assigned to the endpoint.
2628
/// </summary>

src/Http/Routing/src/RouteEndpointDataSource.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
142142
displayName = $"Fallback {displayName}";
143143
}
144144

145-
RequestDelegate? factoryCreatedRequestDelegate = null;
145+
// If we're not a route handler, we started with a fully realized (although unfiltered) RequestDelegate, so we can just redirect to that
146+
// while running any conventions. We'll put the original back if it remains unfiltered right before building the endpoint.
147+
RequestDelegate? factoryCreatedRequestDelegate = isRouteHandler ? null : (RequestDelegate)entry.RouteHandler;
148+
149+
// Let existing conventions capture and call into builder.RequestDelegate as long as they do so after it has been created.
146150
RequestDelegate redirectRequestDelegate = context =>
147151
{
148152
if (factoryCreatedRequestDelegate is null)
@@ -153,26 +157,16 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
153157
return factoryCreatedRequestDelegate(context);
154158
};
155159

160+
// Add MethodInfo and HttpMethodMetadata (if any) as first metadata items as they are intrinsic to the route much like
161+
// the pattern or default display name. This gives visibility to conventions like WithOpenApi() to intrinsic route details
162+
// (namely the MethodInfo) even when applied early as group conventions.
156163
RouteEndpointBuilder builder = new(redirectRequestDelegate, pattern, order)
157164
{
158165
DisplayName = displayName,
159166
ApplicationServices = _applicationServices,
167+
Metadata = { handler.Method },
160168
};
161169

162-
if (isRouteHandler)
163-
{
164-
// Add MethodInfo and HttpMethodMetadata (if any) as first metadata items as they are intrinsic to the route much like
165-
// the pattern or default display name. This gives visibility to conventions like WithOpenApi() to intrinsic route details
166-
// (namely the MethodInfo) even when applied early as group conventions.
167-
builder.Metadata.Add(handler.Method);
168-
}
169-
else
170-
{
171-
// If we're not a route handler, we started with a fully realized (although unfiltered) RequestDelegate, so we can just redirect to that
172-
// while running any conventions. We'll put the original back if it remains unfiltered right before building the endpoint.
173-
factoryCreatedRequestDelegate = (RequestDelegate)entry.RouteHandler;
174-
}
175-
176170
if (entry.HttpMethods is not null)
177171
{
178172
builder.Metadata.Add(new HttpMethodMetadata(entry.HttpMethods));
@@ -203,7 +197,7 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
203197
entrySpecificConvention(builder);
204198
}
205199

206-
if (isRouteHandler || builder.EndpointFilterFactories is { Count: > 0})
200+
if (isRouteHandler || builder.RouteHandlerFilterFactories.Count > 0)
207201
{
208202
var routeParamNames = new List<string>(pattern.Parameters.Count);
209203
foreach (var parameter in pattern.Parameters)
@@ -218,7 +212,7 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
218212
ThrowOnBadRequest = _throwOnBadRequest,
219213
DisableInferBodyFromParameters = ShouldDisableInferredBodyParameters(entry.HttpMethods),
220214
EndpointMetadata = builder.Metadata,
221-
EndpointFilterFactories = builder.EndpointFilterFactories,
215+
RouteHandlerFilterFactories = builder.RouteHandlerFilterFactories,
222216
};
223217

224218
// We ignore the returned EndpointMetadata has been already populated since we passed in non-null EndpointMetadata.

0 commit comments

Comments
 (0)