Remove RequestDelegateFactory call from RouteEndpointBuilder #42703
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
design-proposal
This issue represents a design proposal for a different issue, linked in the description
feature-minimal-hosting
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
The proposal is to remove the call to
RequestDelegateFactory.Create()
I added toRouteEndpointBuilder.Build()
in #42195. The discussion surrounding its inclusion is here. The main impact of this change is that filters run on all endpoints, not just minimal route handlers.Currently, if an endpoint is not a minimal route handler, the method being filtered is just a
RequestDelegate
even if thatRequestDelegate
ultimately called an MVC action or SignalR Hub method with a different method signature.If we only stopped calling
RDF.Create()
inREB.Build()
and made no other changes, this would mean filters would go back to only working with minimal route handlers despite now being applicable to anyIEndpointConventionBuilder
. We could conceivably come up with analyzers that give errors when applied toIEndpointConventionBuilder
s we know won't work, but that still doesn't help that filters applied to groups would only run for minimal route handlers and no other endpoints.Fortunately, in addition to removing
RDF.Create()
fromREB.Build()
, we're planning to add better support for what are now "EndpointFilters" instead of "RouteHandlerFilters" in MVC with #42557. With this PR, the actual MVC action ends the filter pipeline instead of aRequestDelegate
that indirectly invokes the action.Furthermore, we should update our internal
ModelEndpointDataSource
to run filters on theRequestDelegate
s passed toMapGet
and its associated methods. It make sense to useRequestDelegate
as the final method in the filter pipeline in this case, because that's what the developer defined the endpoint with.Some things like
MapHub
just call theRequestDelegate
Map
method overloads. For things like SignalR Hubs that might have another plausible way of filtering the endpoint other than just by filtering theRequestDelegate
it defines, we should probably start using a custom internalEndpointDataSource
that does not run filters on theRequestDelegate
s.Based on early discussions, we don't think we'll be running these filters for Razor Pages or SignalR Hub invocations in .NET 7. If we decide to run filters on more things in .NET 8, we'll need to figure out how to do it in a way that is sufficiently non-breaking way, but we'll cross that bridge when we get there. Any change to filter behavior without an opt-in switch is potentially breaking.
In general, the change here is to make the
EndpointDataSource
implementations solely responsible for running filters. This means that anyone using a customEndpointDataSource
won't have filters run automatically when building theirRouteEndpoint
s, but at least they can run them manually. I think customEndpointDataSource
implementations are relatively rare in any case.The text was updated successfully, but these errors were encountered: