MediatR.Extensions.FluentValidation.AspNetCore 1.1.0

MediatR intgration with FluentValidation validation library using ASP.NET Core.

Install-Package MediatR.Extensions.FluentValidation.AspNetCore -Version 1.1.0
dotnet add package MediatR.Extensions.FluentValidation.AspNetCore --version 1.1.0
<PackageReference Include="MediatR.Extensions.FluentValidation.AspNetCore" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MediatR.Extensions.FluentValidation.AspNetCore --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MediatR.Extensions.FluentValidation.AspNetCore

NuGet
NuGet
license

MediatR extension for FluentValidation using asp.net core

Install

A priori you need to install packages Mediatr and FluentValidation then continue below

Install with nuget

Install-Package MediatR.Extensions.FluentValidation.AspNetCore

Install with .NET CLI

dotnet add package MediatR.Extensions.FluentValidation.AspNetCore

How to use

Setup - Add configuration in startup


public void ConfigureServices(IServiceCollection services)
{
    // Add framework services etc.
    services.AddMvc();
    
    var domainAssembly = typeof(GenerateInvoiceHandler).GetTypeInfo().Assembly;
    // Add MediatR
    services.AddMediatR(domainAssembly);

    //Add FluentValidation
    services.AddFluentValidation(new[] {domainAssembly});
    
    //Add other stuffs
    ...
}

Use

Just to write down validators for IRequest implementation. Validation will be executed before handling IRequestHandler.


public class GenerateInvoiceValidator : AbstractValidator<GenerateInvoiceRequest>
{
    public GenerateInvoiceValidator()
    {
        RuleFor(x => x.Month).LowerThan(13);
        // etc.
    }
}

public class GenerateInvoiceRequest : IRequest
{
    public int Month { get; set; }
}
public class GenerateInvoiceRequestHandler : IRequestHandler<GenerateInvoiceRequest>
{
    public async Task<Unit> Handle(GenerateInvoiceRequest request, CancellationToken cancellationToken)
    {
        // request data has been validated
        ...
    }
}

More examples check FluentValidation docs: https://fluentvalidation.net/start

MediatR.Extensions.FluentValidation.AspNetCore

NuGet
NuGet
license

MediatR extension for FluentValidation using asp.net core

Install

A priori you need to install packages Mediatr and FluentValidation then continue below

Install with nuget

Install-Package MediatR.Extensions.FluentValidation.AspNetCore

Install with .NET CLI

dotnet add package MediatR.Extensions.FluentValidation.AspNetCore

How to use

Setup - Add configuration in startup


public void ConfigureServices(IServiceCollection services)
{
    // Add framework services etc.
    services.AddMvc();
    
    var domainAssembly = typeof(GenerateInvoiceHandler).GetTypeInfo().Assembly;
    // Add MediatR
    services.AddMediatR(domainAssembly);

    //Add FluentValidation
    services.AddFluentValidation(new[] {domainAssembly});
    
    //Add other stuffs
    ...
}

Use

Just to write down validators for IRequest implementation. Validation will be executed before handling IRequestHandler.


public class GenerateInvoiceValidator : AbstractValidator<GenerateInvoiceRequest>
{
    public GenerateInvoiceValidator()
    {
        RuleFor(x => x.Month).LowerThan(13);
        // etc.
    }
}

public class GenerateInvoiceRequest : IRequest
{
    public int Month { get; set; }
}
public class GenerateInvoiceRequestHandler : IRequestHandler<GenerateInvoiceRequest>
{
    public async Task<Unit> Handle(GenerateInvoiceRequest request, CancellationToken cancellationToken)
    {
        // request data has been validated
        ...
    }
}

More examples check FluentValidation docs: https://fluentvalidation.net/start

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.0 191 8/5/2020
1.0.3 110 7/31/2020
1.0.2 2,908 6/18/2020
1.0.1 15,785 9/3/2019
1.0.0 101 9/3/2019