Skip to content

Add .ctor(string) to FromHeaderAttribute and FromQueryAttribute #36418

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

Open
martincostello opened this issue Sep 11, 2021 · 4 comments
Open

Add .ctor(string) to FromHeaderAttribute and FromQueryAttribute #36418

martincostello opened this issue Sep 11, 2021 · 4 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing triage-focus Add this label to flag the issue for focus at triage
Milestone

Comments

@martincostello
Copy link
Member

martincostello commented Sep 11, 2021

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.

@martincostello martincostello added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Sep 11, 2021
@davidfowl davidfowl added old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-minimal-actions Controller-like actions for endpoint routing labels Sep 11, 2021
@rafikiassumani-msft
Copy link
Contributor

Triage: We will evaluate this for .NET7

@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone Sep 13, 2021
@davidfowl davidfowl added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Oct 23, 2021
@ghost
Copy link

ghost commented 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:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@davidfowl davidfowl removed the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Oct 23, 2021
@pranavkm pranavkm added api-suggestion Early API idea and discussion, it is NOT ready for implementation and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Oct 25, 2021
@pranavkm
Copy link
Contributor

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.

@rafikiassumani-msft rafikiassumani-msft added the triage-focus Add this label to flag the issue for focus at triage label Jan 11, 2022
@ghost
Copy link

ghost commented 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.

@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
@captainsafia captainsafia removed the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing triage-focus Add this label to flag the issue for focus at triage
Projects
None yet
Development

No branches or pull requests

6 participants