Skip to content

illunix/MediatR.Extensions.GenerateMediator

Repository files navigation

MediatR.Extensions.GenerateMediator

NuGet NuGet

Generate commands, queries and handlers for MediatR

Installation

PM> Install-Package MediatR.Extensions.GenerateMediator

Usage

Command

[GenerateMediator]
public partial class AddEmployee
{
    public sealed partial record Command;

    public static async Task Handler(Command command)
    {
        // logic
    }
}

Query

[GenerateMediator]
public partial class GetEmployees
{
    public sealed partial record Query;
    
    public sealed record Employee(string FirstName, string LastName);

    public static async Task<IEnumerable<Employee>> Handler()
    {
        // logic
    }
}

Request Validator

If you want add validation to your request first thing you need to do is install fluent validation package

PM> Install-Package FluentValidation.AspNetCore

To use valdation on your request just use AddValidation method in your request, it should look something like this

public sealed partial record Query(string Id)
{
    public static void AddValidation(AbstractValidator<Query> v)
        => v.RuleFor(x => x.Id).NotEmpty();
}

About

Generate command, queries, validators and handlers for MediatR

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages