Class ScalarValueValidationMiddleware
Middleware that creates a validation error collection scope for each request. This enables ValidatingJsonConverter to collect validation errors across the entire request deserialization process.
public sealed class ScalarValueValidationMiddleware
- Inheritance
-
ScalarValueValidationMiddleware
- Inherited Members
- Extension Methods
Examples
Registering the middleware in Program.cs:
app.UseScalarValueValidation();
// ... other middleware
app.MapControllers();
Remarks
This middleware should be registered early in the pipeline, before any middleware that might deserialize JSON request bodies.
For each request:
- Creates a new validation error collection scope
- Allows the request to proceed through the pipeline
- Catches BadHttpRequestException for IScalarValue<TSelf, TPrimitive> parameter binding failures and returns validation problem
- Cleans up the scope when the request completes
Constructors
ScalarValueValidationMiddleware(RequestDelegate)
Creates a new instance of ScalarValueValidationMiddleware.
public ScalarValueValidationMiddleware(RequestDelegate next)
Parameters
nextRequestDelegateThe next middleware in the pipeline.
Methods
InvokeAsync(HttpContext)
Invokes the middleware, wrapping the request in a validation scope.
public Task InvokeAsync(HttpContext context)
Parameters
contextHttpContextThe HTTP context for the request.