Skip to content

Instantly share code, notes, and snippets.

@thangchung
Last active Nov 8, 2021
Embed
What would you like to do?
clean-architecture snippets
app.MapPost("/v1/api/order",
async (SubmitOrder.Command model, ISender sender) => await sender.Send(model));
public record Command : ICommand
{
public string Name { get; init; } = default!;
internal class Validator : AbstractValidator<Command>
{
public Validator()
{
RuleFor(v => v.Name)
.NotEmpty().WithMessage("Name is required.");
}
}
internal class Handler : IRequestHandler<Command, IResult>
{
public Task<IResult> Handle(Command request, CancellationToken cancellationToken)
{
// todo
var resultModel = ResultModel<bool>.Create(true);
return Results.Ok(resultModel);
}
}
}
public record Query : IQuery
{
public string Name { get; init; } = default!;
internal class Validator : AbstractValidator<Query>
{
public Validator()
{
RuleFor(v => v.Name)
.NotEmpty().WithMessage("Name is required.");
}
}
internal class Handler : IRequestHandler<Query, IResult>
{
public Task<IResult> Handle(Query request, CancellationToken cancellationToken)
{
// todo
var resultModel = ResultModel<bool>.Create(true);
return Results.Ok(resultModel);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment