Skip to content

Fix UsePathBase with WAB #42876

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

Merged
merged 6 commits into from
Aug 12, 2022
Merged

Fix UsePathBase with WAB #42876

merged 6 commits into from
Aug 12, 2022

Conversation

BrennanConroy
Copy link
Member

Fixes #38448

UsePathBase can't reference UseRouting (circular reference) so had to employ a bit of a trick to make it work.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

Prior(ish) art for reference: #35426

@BrennanConroy BrennanConroy requested a review from Pilchie as a code owner July 25, 2022 23:17
// ((IApplicationBuilder)WebApplication).New() does not copy globalRouteBuilderKey automatically like it does for all other properties.
builder.Properties[globalRouteBuilderKey] = routeBuilder;
// UseRouting()
if (builder.Properties.TryGetValue(useRoutingKey, out var useRouting) && useRouting is Func<IApplicationBuilder, IApplicationBuilder> useRoutingFunc)
Copy link
Member

Choose a reason for hiding this comment

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

This if should be first and then all the logic happens inside. Else, return the original next.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

I still think we could get rid of the __EndpointRouteBuidler property and just use __UseRouting in its place, but it looks like people have already taken a dependency on routing adding the __EndpointRouteBuildeer key, so maybe it's best to leave the existing keys alone.

I do not like adding more keys just to fix this layering problem, but hopefully this is the end of adding more keys just for rerouting purposes.

@@ -31,6 +32,17 @@ public static IApplicationBuilder UsePathBase(this IApplicationBuilder app, Path
return app;
}

const string globalRouteBuilderKey = "__GlobalEndpointRouteBuilder";
Copy link
Member

Choose a reason for hiding this comment

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

Can we put all these constants in Reroute.cs and share them between all these projects?

@@ -31,6 +32,17 @@ public static IApplicationBuilder UsePathBase(this IApplicationBuilder app, Path
return app;
}

const string globalRouteBuilderKey = "__GlobalEndpointRouteBuilder";
// Only use this path if there's a global router (in the 'WebApplication' case).
Copy link
Member

Choose a reason for hiding this comment

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

I know this isn't new, but is there really a scenario for calling UsePathBase() after route matching with or without WebApplication? I'm not saying we change this now, just curious.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pretty sure we had the same question for some of the other middleware when we initially created this "global routing" concept. And the answer was, why not make it work if it's easy.

Copy link
Member

Choose a reason for hiding this comment

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

And the answer was, why not make it work if it's easy.

Then why didn't we make it work in the non-'WebApplication' case? This isn't feedback on the PR. I think we should leave it how you have it since it's a bit late to change that kind of behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

non WAB doesn't have the global routing concept, and we don't have a way to effectively inject middleware before UseRouting.

@BrennanConroy BrennanConroy merged commit 14c3998 into main Aug 12, 2022
@BrennanConroy BrennanConroy deleted the brecon/pathbase branch August 12, 2022 01:35
@ghost ghost added this to the 7.0-rc1 milestone Aug 12, 2022
@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UsePathBase being ignored
4 participants