MinimalApis.Extensions icon indicating copy to clipboard operation
MinimalApis.Extensions copied to clipboard

Add support for binding parameter objects

Open DamianEdwards opened this issue 3 years ago • 0 comments

From this tweet thread.

Parameters of a type marked with an IBindProperties interface will have its top-level members bound as if they were parameters on the route handler delegate, including all inference rules and source attribute support, e.g. [FromRoute], etc.

app.MapGet("/products", (PagingData pagingData) =>
{
});

app.MapGet("/search/{term}", (string term, PagingData pagingData) =>
{
});

class PagingData : IBindProperties
{
  public int PageIndex { get; set; }
  public int PageSize { get; set; }
}
app.MapGet("/product/{id}", (ProductCommand command) =>
{
});

class ProductCommand : IBindProperties
{
    public int Id { get; set; }
    public int PageIndex { get; set; }
    public Product Product { get; set; }
    public ILogger<ProductCommand> Logger { get; set; }
}


DamianEdwards avatar Jan 28 '22 18:01 DamianEdwards