Skip to content
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

Routing system should introduce some abstraction for converting route parameters to strings. #58416

Open
1 task done
voroninp opened this issue Oct 14, 2024 · 0 comments
Open
1 task done
Milestone

Comments

@voroninp
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am working with typed ids:

public readonly record struct FooId(Guid Value);

If I use this value as a route parameter value and do not override ToString it is converted to string as FooId { Value = '....' }. That is obviously not what I want to have in a generated URL.

IMO, framework should not force my types to have a certain behavior. Writing parameter value to a URL is effectively a serialization, hence there should be the same level of flexibility/extensibility.

While framework offers outbound parameter transformers, they are not connected to the types of parameter values.

Describe the solution you'd like

I'd like ASP.NET to introduce a specific interface:

public interface IRouteParaemterValueStringConverter<TParameterValue>
{
    string Convert(TParameterValue value);
}

Its default implementation can just convert to string.

Additional context

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Oct 14, 2024
@javiercn javiercn added area-routing and removed area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Oct 14, 2024
@javiercn javiercn added this to the Backlog milestone Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants