-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Improvements to DynamicRouteValueTransformer #21471
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
Comments
See: #21471 This change just include the product-side changes and just for controllers. This addresses most the major gaps our partners have found with dynamic route value transformers. Doesn't include anything order-related.
Oh i would really need this feature too. But for pages |
@rynowak - will the following scenario be covered with these enhancements? Localization using a PageRouteModelConvention ie: Using a DynamicRouteValueTransformer as pages defined in headless CMS: Gives: Not sure if relevant but I notice there are routes set up other than the DynamicPageRoute even though I have commented out: Minimal repro: Can log new issue if outside the scope of the above enhancements. Is there a workaround? TIA |
Linking this here in case this can be resoled as part of these improvements: #16965 |
See: #21471 This change just include the product-side changes and just for controllers. This addresses most the major gaps our partners have found with dynamic route value transformers. Doesn't include anything order-related.
Summary
3.1 Introduced DynamicRouteValueTransformer - a feature that allows you to use a custom endpoint to dynamically select a controller-action or a razor page.
This is useful when you want to create a slug route that accesses the database to choose where to go, or when you're layering another framework on top of MVC (OData).
Now that we've had a chance to get some feedback on it's clear that we're missing a few features that ought to be there.
Context
The way that
DynamicRouteValueTransformer
is hooked up, there's no way to pass additional context to it.DynamicRouteValueTransformer
comes from DI.If you have multiple endpoints that use the same transformer type, you can't pass any data to them, because they come from DI. You effectively need a distinct type for each instance, which isn't a solution. Both OData and Orchard hit this issue.
Filtering
You might also want to do some filtering based on the results of your transformer. MVC resolves the matching endpoints based on the set of route values returned by a transformer, but the transformer can't do any filtering, or see the endpoints that resulted.
See: https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/Mvc.Core/src/Routing/DynamicControllerEndpointMatcherPolicy.cs#L121
Writing a separate policy to handle this doesn't work well. The transformer has context that is lost when you get past this phase:
A policy that runs later can't see which endpoints came from the transformer, and can't store context because policies are singletons.
Ordering
The methods we provide for registering transformers don't support providing an Order. That's a fairly important thing when considering that transformers will be interleaved with other MVC endpoints.
However
MapDynamicControllerRoute
doesn't follow the same ordering rules asMapControllerRoute
- it always uses order 0.aspnetcore/src/Mvc/Mvc.Core/src/Builder/ControllerEndpointRouteBuilderExtensions.cs
Line 481 in 6ce8a87
We should consider a breaking change to make
MapDynamicControllerRoute
follow the ordering rules ofMapControllerRoute
and also allow fine-grained control over the order value.Fixes
We should add some functionality like the following:
And the ability to pass in state:
The text was updated successfully, but these errors were encountered: