Skip to content

AdaskoTheBeAsT/AdaskoTheBeAsT.FluentValidation.MediatR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AdaskoTheBeAsT.FluentValidation.MediatR

FluentValidation behavior for MediatR

Badges

CodeFactor Build Status Azure DevOps tests Azure DevOps coverage Quality Gate Status Sonar Tests Sonar Test Count Sonar Test Execution Time Sonar Coverage Nuget

Usage

It can be used in combination with AdaskoTheBeAsT.FluentValidation.SimpleInjector AdaskoTheBeAsT.MediatR.SimpleInjector

Validators registered as single

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<,>));
        });

Validators registered as collection

    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<,>));
        });

About

FluentValidation behavior for MediatR

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages