-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Exclude regex and alpha constraints when SlimBuilder is used. #46227
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
Exclude regex and alpha constraints when SlimBuilder is used. #46227
Conversation
Bunch of changes to make unit tests pass. Still need to do some more testing to see if this breaks any typical usage scenarios. I'm feeling great about this change at the moment - I think it carries some risk. |
src/Http/Routing/test/UnitTests/Matching/DfaMatcherBuilderTest.cs
Outdated
Show resolved
Hide resolved
src/Http/Routing/test/UnitTests/Matching/DfaMatcherConformanceTest.cs
Outdated
Show resolved
Hide resolved
We shouldn't change what AddRouting does. The Slim builder should call a different API that removes these constraints. None of the tests should require updating and a new test that uses the new API should be added. |
What's the error message presented to the user if someone uses the "slim" set of constraints but references Here is a crazy idea: The slim set of constraints register a custom The error message could be something like
A custom error can make it very obvious to users what is going on and how to fix their app. |
See this
This isn't crazy, it's good 😄. What would be crazy is if we could just make it work. |
0b9fe16
to
a7d32fd
Compare
We're already calling UseRouting here: aspnetcore/src/DefaultBuilder/src/WebHost.cs Line 260 in 15d5f0c
BTW @eerhardt this method name is very confusing: aspnetcore/src/DefaultBuilder/src/WebHost.cs Line 233 in 15d5f0c
It does more than adding Kestrel, we should rename it. |
Aside from some renames and perhaps alternative placement of |
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.
Needs unit tests of what happens when a regex constraint is used in a slim builder app - both with and without registering the regex constraint.
Also, did what are your thoughts on providing a friendly error message like I described here - #46227 (comment)
src/Http/Routing/src/DependencyInjection/RoutingServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
…teConstraint and add test to that effect.
src/Http/Routing/src/DependencyInjection/RoutingServiceCollectionExtensions.cs
Outdated
Show resolved
Hide resolved
src/Http/Routing/test/UnitTests/RoutingServiceCollectionExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/Http/Routing/test/UnitTests/RoutingServiceCollectionExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/Http/Routing/src/Constraints/RegexErrorStubRouteConstraint.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Eric Erhardt <[email protected]>
…ionsTests.cs Co-authored-by: Stephen Halter <[email protected]>
Co-authored-by: Eric Erhardt <[email protected]>
Co-authored-by: Stephen Halter <[email protected]>
Co-authored-by: James Newton-King <[email protected]>
Co-authored-by: James Newton-King <[email protected]>
Background and Motivation
Modify
RouteOptions
to not automatically add theRegexRouteConstraint
. InsteadAddRouting(...)
is modified to call a new method calledAddRoutingCore(...)
which does everything thatAddRouting(...)
does, but then adds theRegexRouteConstraint
back in toRouteOptions
.Proposed API
namespace Microsoft.Extensions.DependencyInjection; public static class RoutingServiceCollectionExtensions { + public static IServiceCollection AddRoutingCore(this IServiceCollection services); }
Usage Examples
We will use
CreateSlimBuilder(...)
to callAddRoutingOptions(...)
. See PR contents for an example.Alternative Designs
This PR currently includes an
AddRegexConstraint(...)
method on the PR, this will likely be removed in favor of just adding theRegexRouteConstraint
via the expose dictionary.Risks
Could be somewhat confusing as to why we are excluding just the reg-ex constraint.