Skip to main content
Table of Contents

Class ValidationServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Stratara.Validation.dll

DI extensions that register the Stratara validation pipeline behavior and discover IValidator<T> implementations.

public static class ValidationServiceCollectionExtensions
Inheritance
ValidationServiceCollectionExtensions
Inherited Members

Methods

AddStrataraValidation(IServiceCollection)

Register the validation pipeline behaviors for both request shapes (IRequest and IRequest<TResult>).

public static IServiceCollection AddStrataraValidation(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection to mutate.

Returns

IServiceCollection

The same service collection, to enable chaining.

Examples

builder.Services
    .AddStrataraValidation()
    .AddValidatorsFromAssemblyContaining<IAppMarker>();

Remarks

Call this before any other AddPipelineBehavior* registration so validation runs as the outermost behavior — rejecting invalid requests before authorization, auditing, or the handler execute. Pair with AddValidatorsFromAssemblyContaining<T>(IServiceCollection) to register the concrete validators.

AddValidatorsFromAssemblyContaining<T>(IServiceCollection)

Scan the assembly containing T and register every concrete IValidator<T> implementation as a scoped service against each closed IValidator<T> interface it implements.

public static IServiceCollection AddValidatorsFromAssemblyContaining<T>(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection to mutate.

Returns

IServiceCollection

The same service collection, to enable chaining.

Type Parameters

T

A marker type from the assembly to scan. Typically a domain marker interface.

Examples

Discovery alone does not enforce anything — the behaviour is what runs them:

services.AddStrataraValidation();
services.AddValidatorsFromAssemblyContaining<OpenAccountValidator>();