FluentValidation behavior for MediatR
It can be used in combination with AdaskoTheBeAsT.FluentValidation.SimpleInjector AdaskoTheBeAsT.MediatR.SimpleInjector
There should be only one validator per target If there is multiple combined validators needed then prepare one which will gather all rules from other based on Fluent Validation Including Rules and mark all sub validators with attribute SkipValidatorRegistrationAttribute.
container.AddFluentValidation(
cfg =>
{
cfg.WithAssembliesToScan(assemblies);
cfg.AsScoped();
cfg.RegisterAsSingleValidator(); // can be skipped as it is default
});
container.AddMediatR(
cfg =>
{
cfg.WithAssembliesToScan(assemblies);
cfg.UsingBuiltinPipelineProcessorBehaviors(true);
cfg.UsingPipelineProcessorBehaviors(typeof(FluentValidationPipelineBehavior<,>));
cfg.UsingStreamPipelineBehaviors(typeof(FluentValidationStreamPipelineBehavior<,>));
});
container.AddFluentValidation(
cfg =>
{
cfg.WithAssembliesToScan(assemblies);
cfg.AsScoped();
cfg.RegisterAsValidatorCollection();
});
container.AddMediatR(
cfg =>
{
cfg.WithAssembliesToScan(assemblies);
cfg.UsingBuiltinPipelineProcessorBehaviors(true);
cfg.UsingPipelineProcessorBehaviors(typeof(FluentValidationCollectionPipelineBehavior<,>));
cfg.UsingStreamPipelineBehaviors(typeof(FluentValidationCollectionStreamPipelineBehavior<,>));
});