Skip to content

Add support for route handler filter factories#40667

Merged
captainsafia merged 11 commits into
dotnet:mainfrom
captainsafia:ef-factory
Mar 16, 2022
Merged

Add support for route handler filter factories#40667
captainsafia merged 11 commits into
dotnet:mainfrom
captainsafia:ef-factory

Conversation

@captainsafia
Copy link
Copy Markdown
Contributor

@captainsafia captainsafia commented Mar 11, 2022

Closes #40513

@ghost ghost added the area-runtime label Mar 11, 2022
Comment thread src/Http/Http.Abstractions/src/RouteHandlerFilterContext.cs Outdated
Comment thread src/Http/Http.Abstractions/src/RouteHandlerFilterDelegate.cs Outdated
Comment thread src/Http/Routing/src/Builder/RouteHandlerFilterExtensions.cs Outdated
@captainsafia captainsafia added old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels and removed area-runtime labels Mar 11, 2022
Comment thread src/Http/Routing/src/Builder/RouteHandlerFilterExtensions.cs Outdated
Comment thread src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs Outdated
Comment thread src/Http/Routing/src/Builder/RouteHandlerFilterExtensions.cs Outdated
Comment thread src/Http/Http.Abstractions/src/RouteHandlerFilterDelegate.cs Outdated
Comment thread src/Http/Routing/src/Builder/RouteHandlerFilterExtensions.cs Outdated
@captainsafia captainsafia requested a review from a team March 12, 2022 03:26
Co-authored-by: David Fowler <davidfowl@gmail.com>
@captainsafia captainsafia marked this pull request as ready for review March 12, 2022 03:29
Comment thread src/Http/Http.Extensions/src/RequestDelegateFactory.cs Outdated
Copy link
Copy Markdown
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a test be added that asserts some endpoint metadata?

Comment thread src/Http/Http.Abstractions/src/RouteHandlerContext.cs Outdated
Comment thread src/Http/Routing/src/Builder/RouteHandlerFilterExtensions.cs Outdated
/// <returns>An awaitable result of calling the handler and apply
/// any modifications made by filters in the pipeline.</returns>
ValueTask<object?> InvokeAsync(RouteHandlerFilterContext context, Func<RouteHandlerFilterContext, ValueTask<object?>> next);
ValueTask<object?> InvokeAsync(RouteHandlerInvocationContext context, RouteHandlerFilterDelegate next);
Copy link
Copy Markdown
Member

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 RouteHandlerContext parameter? We can try to approve this over email if we like it.

Suggested change
ValueTask<object?> InvokeAsync(RouteHandlerInvocationContext context, RouteHandlerFilterDelegate next);
ValueTask<object?> InvokeAsync(RouteHandlerContext routeContext, RouteHandlerInvocationContext invocationContext, RouteHandlerFilterDelegate next);

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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 RouteHandlerContext as an argument to the object factory generated when the user utilizes the AddFilter<TFilterType>() overload.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up: #40724

Comment thread src/Http/Routing/src/Builder/RouteHandlerFilterExtensions.cs Outdated
Comment thread src/Http/Http.Abstractions/src/RouteHandlerContext.cs Outdated
Comment thread src/Http/Http.Abstractions/src/RouteHandlerInvocationContext.cs Outdated
/// provided to a route handler.
/// </summary>
public class RouteHandlerInvocationContext
public sealed class RouteHandlerInvocationContext
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't seal this one. We'll end up un sealing it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment thread src/Http/Routing/src/Builder/RouteHandlerFilterExtensions.cs Outdated
Comment thread src/Http/Routing/src/Builder/RouteHandlerFilterExtensions.cs Outdated
@captainsafia captainsafia enabled auto-merge (squash) March 16, 2022 00:23
@captainsafia captainsafia merged commit 5fa80eb into dotnet:main Mar 16, 2022
@ghost ghost added this to the 7.0-preview3 milestone Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for filter factory to minimal APIs

4 participants