Skip to content

RequestDelegateFactory (minimal APIs) should support discovering TryParse & BindAsync methods from inherited types #36663

Closed
@DamianEdwards

Description

@DamianEdwards

E.g. make something like this work:

app.MapPost("/widget", (CreateWidgetDTO dto) =>
{
    // Use the dto
});

public abstract class DTO<T>
{
    // typeof(T) must equal ParameterInfo.Type otherwise we throw
    public static T BindAsync(HttpContext context, ParameterInfo parameter)
    {
        // Use reflection to bind the properties on T
    }
}

public class CreateWidgetDTO : DTO<CreateWidgetDTO>
{
    [FromRoute]
    public string? Name { get; set; }

    [FromQuery]
    public int Id { get; set; }
}

Metadata

Metadata

Assignees

Labels

area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions