Last active
November 8, 2021 09:52
-
-
Save thangchung/6bccc511cd8aaf87179d4753b79a2424 to your computer and use it in GitHub Desktop.
clean-architecture snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.MapPost("/v1/api/order", | |
async (SubmitOrder.Command model, ISender sender) => await sender.Send(model)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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