Table of Contents

Class ScalarValueValidationEndpointFilter

Namespace
Trellis.Asp
Assembly
Trellis.Asp.dll

An endpoint filter that checks for scalar value validation errors collected during JSON deserialization. For Minimal APIs, this filter returns validation problem results when validation errors are detected.

public sealed class ScalarValueValidationEndpointFilter : IEndpointFilter
Inheritance
ScalarValueValidationEndpointFilter
Implements
Inherited Members
Extension Methods

Examples

app.MapPost("/users", (RegisterUserDto dto) => ...)
   .AddEndpointFilter<ScalarValueValidationEndpointFilter>();

Remarks

This filter works in conjunction with ValidatingJsonConverter and ValidationErrorsContext to provide comprehensive validation error handling.

Unlike the MVC ScalarValueValidationFilter, this filter is designed for Minimal APIs and returns IResult instead of manipulating ModelStateDictionary.

Methods

InvokeAsync(EndpointFilterInvocationContext, EndpointFilterDelegate)

Invokes the filter, checking for validation errors collected during JSON deserialization.

public ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)

Parameters

context EndpointFilterInvocationContext

The endpoint filter invocation context.

next EndpointFilterDelegate

The next filter in the pipeline.

Returns

ValueTask<object>

A validation problem result if validation errors exist, otherwise the result from the next filter.