Super Simplify validation Minimal APIs in ASP.NET Core 7 or later with Short-circuit endpoint executions.
public sealed class CreateProductDto
{
public string Title { get; set; }
}
public class CreateProductValidator : AbstractValidator<CreateProductDto>
{
public CreateProductValidator()
{
RuleFor(x => x.Title)
.NotEmpty();
}
}
builder.Services.AddScoped<IValidator<CreateProductDto>,CreateProductValidator>();
app.MapPost("/products/create", async (CreateProductDto product) =>
{
// code command execution
}).Validator<CreateProductDto>();