Skip to content

Allow to bind records with both primary constructor and properties via AsParameters #62226

@Dreamescaper

Description

@Dreamescaper

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'm adding pagination support to my app. I want to avoid adding limit/offset parameters to every request, so I've added base record type PagedRequest:

public abstract record PagedReqeust
{
     public int? Limit { get; init; }
     public int? Offset { get; init; }
}

So I could use it like this:

public record MyRequest(string MyParam1, string MyParam2) : PagedRequest;

app
    .MapGet("/my-endpoint", ([AsParameters] MyRequest request) => { /* handle it */  });

Unfortunately, it doesn't work this way. Limit and Offset properties stay null even when query params provided.

Describe the solution you'd like

Would be nice if [AsParameters] taken properties into account when primary constructor is present.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdffeature-rdg

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions