Table of Contents

Class ScalarValueValidationFilter

Namespace
Trellis.Asp
Assembly
Trellis.Asp.dll

An action filter that checks for validation errors collected during JSON deserialization and validates IScalarValue<TSelf, TPrimitive> route/query parameters. Returns a ValidationProblemDetails response — 422 Unprocessable Content for Trellis-driven semantic validation failures (composite VO converter, scalar VO TryCreate, ValidationErrorsContext-collected errors) per RFC 9110 §15.5.21, and 400 Bad Request for plain JsonExceptions where the bytes aren't valid JSON per RFC 9110 §15.5.1. When both occur on the same request, 400 wins.

public sealed class ScalarValueValidationFilter : IActionFilter, IOrderedFilter, IFilterMetadata
Inheritance
ScalarValueValidationFilter
Implements
Inherited Members
Extension Methods

Examples

The filter is typically registered globally in Program.cs:

builder.Services.AddControllers(options =>
{
    options.Filters.Add<ScalarValueValidationFilter>();
});

Remarks

This filter works in conjunction with ValidatingJsonConverterFactory to provide automatic validation of scalar values in request DTOs. The converter collects validation errors during deserialization, and this filter checks for errors before the action executes.

Additionally, this filter validates route and query string parameters that are IScalarValue<TSelf, TPrimitive> types. When model binding fails for these types (resulting in a null parameter), the filter returns a validation error.

If validation errors are detected:

  • The action is short-circuited (not executed)
  • A ValidationProblemDetails response is returned — 422 for Trellis semantic validation failures, 400 for plain JSON syntax errors (with 400 winning on mixed requests)
  • The response format matches ASP.NET Core's standard validation error format

Properties

Order

Gets the order value for filter execution. This filter runs early to catch validation errors before other filters or the action execute.

public int Order { get; }

Property Value

int

Methods

OnActionExecuted(ActionExecutedContext)

Called after the action executes, before the action result.

public void OnActionExecuted(ActionExecutedContext context)

Parameters

context ActionExecutedContext

The ActionExecutedContext.

OnActionExecuting(ActionExecutingContext)

Called before the action executes, after model binding is complete.

public void OnActionExecuting(ActionExecutingContext context)

Parameters

context ActionExecutingContext

The ActionExecutingContext.