[Blazor] Add Blazor Web Endpoints to the endpoint data source#57086
[Blazor] Add Blazor Web Endpoints to the endpoint data source#57086
Conversation
| convention(endpoint); | ||
| } | ||
|
|
||
| foreach (var convention in _finallyConventions) |
There was a problem hiding this comment.
RazorComponentEndpointDataSource ought to implement GetGroupedEndpoints and call _groupConventions first and _groupFinallyConventions last like RouteEndpointDataSource, ControllerActionEndpointDataSource, and PageActionEndpointDataSource do.
aspnetcore/src/Http/Routing/src/RouteEndpointDataSource.cs
Lines 195 to 202 in 876e36d
aspnetcore/src/Mvc/Mvc.Core/src/Routing/ActionEndpointFactory.cs
Lines 346 to 350 in 876e36d
The default virtual implementation of GetGroupedEndpoints provides an approximation of this, but it's not as good because group conventions are forced to run after the _conventions and _finallyConventions associated with MapRazorComponent. It might not be super relevant for these endpoints, but I know WithOpenApi looks for already-added metadata in its convention callbacks. The default implementation also prevents a group from injecting any "inner" endpoint filters.
aspnetcore/src/Http/Routing/src/EndpointDataSource.cs
Lines 67 to 72 in 5c2dce5
These are pretty niche problems. We tried to make the default implementation of GetGroupedEndpoints as good as possible, but we might as well align behavior with our other EndpointDataSources for maximum correctness.
There was a problem hiding this comment.
@halter73 I'm going to consider adding support for that outside of scope for this change. I've filed #57120 to track it separately, since we are planning on patching this, I want to keep this PR small.
We can discuss the other one separately, as we haven't seen it used in conjunction with MapGroup in the wild I think in a way that causes problems.
halter73
left a comment
There was a problem hiding this comment.
Indecently, my comment about the default implementation of GetGroupedEndpoints demonstrates how you could work around #57086 today by doing something like the following:
var blazorGroup = app.MapGroup("");
blazorGroup.MapRazorComponent<App>();
.AddInteractiveServerRenderMode();
blazorGroup.Add(endpointBuilder =>
{
if (endpointBuilder is RouteEndpointBuilder routeEndpointBuilder)
{
if (string.Equals(routeEndpointBuilder.RoutePattern.RawText, "_framework/blazor.web.js", StringComparison.OrdinalIgnoreCase))
{
routeEndpointBuilder.Metadata.Add(new AllowAnonymousAttribute());
}
}
});This works because the default GetGroupedEndpoints creates RouteEndpointBuilder's out of RouteEndpoints retuned by the abstract Endpoints factory. I still think this is worth fixing and backporting to 8.0 though.
MackinnonBuck
left a comment
There was a problem hiding this comment.
This looks good to me, but I'll wait to approve until after Stephen's comments are resolved.
Register the
blazor.web.jsfile and theopaque-redirectendpoints into the endpoint data source.Fixes #57081