-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add support for route handler filter factories #40667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a5cb7e4
39b8721
ddd5b59
4b39ed4
fb6fefd
e8032e2
c600fc4
a55381f
5f060d3
87adb2a
a2c2452
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Reflection; | ||
|
|
||
| namespace Microsoft.AspNetCore.Http; | ||
|
|
||
| /// <summary> | ||
| /// Represents the information accessible via the route handler filter | ||
| /// API when the user is constructing a new route handler. | ||
| /// </summary> | ||
| public sealed class RouteHandlerContext | ||
| { | ||
| /// <summary> | ||
| /// Creates a new instance of the <see cref="RouteHandlerContext"/>. | ||
| /// </summary> | ||
| /// <param name="methodInfo">The <see cref="MethodInfo"/> associated with the route handler of the current request.</param> | ||
| /// <param name="endpointMetadata">The <see cref="EndpointMetadataCollection"/> associated with the endpoint the filter is targeting.</param> | ||
| public RouteHandlerContext(MethodInfo methodInfo, EndpointMetadataCollection endpointMetadata) | ||
| { | ||
| MethodInfo = methodInfo; | ||
| EndpointMetadata = endpointMetadata; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="MethodInfo"/> associated with the current route handler. | ||
| /// </summary> | ||
| public MethodInfo MethodInfo { get; } | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="EndpointMetadataCollection"/> associated with the current endpoint. | ||
| /// </summary> | ||
| public EndpointMetadataCollection EndpointMetadata { get; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.AspNetCore.Http; | ||
|
|
||
| /// <summary> | ||
| /// A delegate that is applied as a filter on a route handler. | ||
| /// </summary> | ||
| /// <param name="context">The <see cref="RouteHandlerInvocationContext"/> associated with the current request.</param> | ||
| /// <returns> | ||
| /// A <see cref="ValueTask"/> result of calling the handler and applying any modifications made by filters in the pipeline. | ||
| /// </returns> | ||
| public delegate ValueTask<object?> RouteHandlerFilterDelegate(RouteHandlerInvocationContext context); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,14 @@ namespace Microsoft.AspNetCore.Http; | |
| /// Provides an abstraction for wrapping the <see cref="HttpContext"/> and parameters | ||
| /// provided to a route handler. | ||
| /// </summary> | ||
| public class RouteHandlerFilterContext | ||
| public sealed class RouteHandlerInvocationContext | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't seal this one. We'll end up un sealing it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed this during API review. Unsealing doesn't have a cost, but sealing does so we are taking the more flexible option to start. If we ship the parameters change in preview4, it shouldn't be too bad. |
||
| { | ||
| /// <summary> | ||
| /// Creates a new instance of the <see cref="RouteHandlerFilterContext"/> for a given request. | ||
| /// Creates a new instance of the <see cref="RouteHandlerInvocationContext"/> for a given request. | ||
| /// </summary> | ||
| /// <param name="httpContext">The <see cref="HttpContext"/> associated with the current request.</param> | ||
| /// <param name="parameters">A list of parameters provided in the current request.</param> | ||
| public RouteHandlerFilterContext(HttpContext httpContext, params object[] parameters) | ||
| public RouteHandlerInvocationContext(HttpContext httpContext, params object[] parameters) | ||
| { | ||
| HttpContext = httpContext; | ||
| Parameters = parameters; | ||
|
|
@@ -28,7 +28,7 @@ public RouteHandlerFilterContext(HttpContext httpContext, params object[] parame | |
| /// <summary> | ||
| /// A list of parameters provided in the current request to the filter. | ||
| /// <remarks> | ||
| /// This list is not read-only to premit modifying of existing parameters by filters. | ||
| /// This list is not read-only to permit modifying of existing parameters by filters. | ||
| /// </remarks> | ||
| /// </summary> | ||
| public IList<object?> Parameters { get; } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we feel about adding a
RouteHandlerContextparameter? We can try to approve this over email if we like it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? This should e a constructor argument, like middleware has the magic next no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does middleware pass the magic
next?The implementation I just pushed passes the
RouteHandlerContextas an argument to the object factory generated when the user utilizes theAddFilter<TFilterType>()overload.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up: #40724