Endpoint filters reduce validation noise in Minimal APIs.
public class ValidateFilter : IEndpointFilter
{
public Task<object?> InvokeAsync(EndpointFilterInvocationContext ctx, EndpointFilterDelegate next)
{
var model = ctx.GetArgument(0);
Validator.ValidateObject(model, new());
return next(ctx);
}
}
They keep endpoints clean, reusable, and testable.
