-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add RouteValueDictionary overloads to Http.Results #46542
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
Labels
api-approved
API was approved in API review, it can be implemented
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
cc @davidfowl |
API Review Notes:
API Approved! namespace Microsoft.AspNetCore.Http;
public static partial class Results
{
+ public static IResult RedirectToRoute(string? routeName, RouteValueDictionary? routeValues, bool permanent = false, bool preserveMethod = false, string? fragment = null);
+ public static IResult CreatedAtRoute(string? routeName, RouteValueDictionary? routeValues, object? value = null);
+ public static IResult CreatedAtRoute<TValue>(string? routeName, RouteValueDictionary? routeValues, TValue? value = default);
+ public static IResult AcceptedAtRoute(string? routeName, RouteValueDictionary? routeValues, object? value = null);
+ public static IResult AcceptedAtRoute<TValue>(string? routeName, RouteValueDictionary? routeValues, TValue? value = default);
}
public static partial class TypedResults
{
+ public static RedirectToRouteHttpResult RedirectToRoute(string? routeName, RouteValueDictionary? routeValues, bool permanent = false, bool preserveMethod = false, string? fragment = null);
+ public static CreatedAtRoute CreatedAtRoute(string? routeName, RouteValueDictionary? routeValues);
+ public static CreatedAtRoute<TValue> CreatedAtRoute<TValue>(TValue? value, string? routeName, RouteValueDictionary? routeValues);
+ public static AcceptedAtRoute AcceptedAtRoute(string? routeName, RouteValueDictionary? routeValues);
+ public static AcceptedAtRoute<TValue> AcceptedAtRoute<TValue>(TValue? value, string? routeName, RouteValueDictionary? routeValues);
}
namespace Microsoft.AspNetCore.Http.HttpResults;
public sealed partial class RedirectToRouteHttpResult : IResult
{
- public RouteValueDictionary? RouteValues { get; }
+ public RouteValueDictionary RouteValues { get; }
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
api-approved
API was approved in API review, it can be implemented
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Background and Motivation
Results
andTypedResults
have methods that use reflection to create route values. These have all been annotated as unsafe.We have previously worked around this problem by adding overloads that take
RouteValueDictionary
. Values can be explicitly added to the dictionary, and the dictionary is then passed to routing. This is a trimming and AOT-safe alternative.Proposed API
Usage Examples
Alternative Designs
Generic type parameter for route values was explored in #46082. For example:
public static partial class Results { + public static IResult CreatedAtRoute<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TRouteValues>(string? routeName, TRouteValues routeValues, object? value = null); }
It doesn't require converting the route values object into a
RouteValueDictionary
, but it has some problems:object
and then used withCreatedAtRoute<TRouteValues>
, its properties aren't preserved.CreatedAtRoute<TRouteValues>
overload and aCreatedAtRoute<TValue>
overload. Code that explicitly specifies the generic type when callingCreatedAtRoute
could cause an ambiguous method compiler error.For example:
Risks
There are a lot of overloads, optional parameters and nullable types. It is possible to create method overloads that are ambiguous.
To avoid that:
RouteValueDictionary
args never have a default value. It must be specified.The text was updated successfully, but these errors were encountered: