MinimalApis.Extensions
MinimalApis.Extensions copied to clipboard
Add support for binding parameter objects
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; }
}