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 400 Bad Request response with validation problem details when validation fails.

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 400 Bad Request response with validation problem details is returned
  • 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.