Generate commands, queries and handlers for MediatR
PM> Install-Package MediatR.Extensions.GenerateMediator
[GenerateMediator]
public partial class AddEmployee
{
public sealed partial record Command;
public static async Task Handler(Command command)
{
// logic
}
}
[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
}
}
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();
}