Skip to content

bioyeneye/MediatR.Extensions.FluentValidation.Core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MediatR.Extensions.FluentValidation.Core

NuGet NuGet license

MediatR extension for FluentValidation using asp.net core

Install with nuget

Install-Package MediatR.Extensions.FluentValidation.Core

Install with .NET CLI

dotnet add package MediatR.Extensions.FluentValidation.Core

How to use

Setup - Add configuration in startup

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services etc.
    services.AddMvc();
    
    // Add MediatR
    services.AddMediatR(typeof(Startup));

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

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseHttpsRedirection();

    //Add FluentValidation Middleware
    app.UseFluentValidationExceptionHandler();

   //Add other stuffs
    ...
}

Sample Validation

public class CreateTodoCommandValidator : AbstractValidator<CreateTodoCommand>
{
    public CreateTodoCommandValidator()
    {
        RuleFor(x => x.Task)
            .NotEmpty();
    }
}

public class CreateTodoCommand : IRequest<Todo>
{
    public CreateTodoCommand(string task, bool isCompleted)
    {
        Task = task;
        IsCompleted = isCompleted;
    }

    public string Task { get; }
    public bool IsCompleted { get;}
}

About

MediatR extension for FluentValidation using asp.net core

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages