Skip to content

VitreousValidationServiceCollectionExtensions class

Namespace: Vitreous.FluentValidation
Assembly: Vitreous.FluentValidation.dll

Extension methods to register the Vitreous FluentValidation pipeline behaviors.

public static class VitreousValidationServiceCollectionExtensions

object ← VitreousValidationServiceCollectionExtensions

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

AddVitreousValidation(IServiceCollection)

Section titled “ AddVitreousValidation(IServiceCollection)”

Registers ValidationBehavior<TMessage, TResult> for commands and queries and StreamValidationBehavior<TMessage, TResult> for stream queries. Each runs the message’s IValidator<T> services before the handler and returns Validation when they fail. Calling this more than once does nothing.

public static IServiceCollection AddVitreousValidation(this IServiceCollection services)

services IServiceCollection

IServiceCollection

Validators are not registered by this method. Register them yourself, for example with services.AddValidatorsFromAssemblyContaining<Program>() from the FluentValidation.DependencyInjectionExtensions package.

Behaviors run in registration order, outermost first. Call this before AddVitreousCaching() so that invalid queries never reach the cache.