Open
Description
Background and Motivation
When using Minimal APIs, using explicit query string or header parameter names using attributes requires a less-minimal amount of attribute declaration that would be possible if the relevant attributes did not only have a default constructor.
Proposed API
namespace Microsoft.AspNetCore.Mvc
{
public static class FromHeaderAttribute
{
+ public FromHeaderAttribute(string name)
}
public static class FromQueryAttribute
{
+ public FromQueryAttribute(string name)
}
public static class FromRouteAttribute
{
+ public FromRouteAttribute(string name)
}
}
Usage Examples
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/search", (
[FromQuery("q")] string? query,
[FromHeader("User-Agent")] string? userAgent) =>
{
return $@"You searched for ""{query}"" using ""{userAgent}"".";
});
app.Run();
Alternative Designs
None, retain the existing usage patterns.
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/search", (
[FromQuery(Name = "q")] string? query,
[FromHeader(Name = "User-Agent")] string? userAgent) =>
{
return $@"You searched for ""{query}"" using ""{userAgent}"".";
});
app.Run();
Risks
None that I'm aware of.
EDIT: Added FromRouteAttribute
too.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
rafikiassumani-msft commentedon Sep 13, 2021
Triage: We will evaluate this for .NET7
ghost commentedon Oct 23, 2021
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:
pranavkm commentedon Oct 25, 2021
API review:
@martincostello while we think this API proposal is valid, we want to wait and see given a) a solution exists using the property (b) we might want to do something to not use MVC attributes with route handlers. We'll put this in our backlog for now and bring this back up part way thru 7.0 once we have had a better sense for how these attributes get used.
ghost commentedon Jun 14, 2022
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.