50 lines
933 B
Markdown
50 lines
933 B
Markdown
# Quick Snippets
|
|
|
|
Common code snippets.
|
|
|
|
## Basic Command
|
|
|
|
```csharp
|
|
public record CreateOrderCommand
|
|
{
|
|
public int CustomerId { get; init; }
|
|
}
|
|
|
|
public class CreateOrderHandler : ICommandHandler<CreateOrderCommand, int>
|
|
{
|
|
public async Task<int> HandleAsync(CreateOrderCommand command, CancellationToken ct)
|
|
{
|
|
// Handle command
|
|
return orderId;
|
|
}
|
|
}
|
|
|
|
// Registration
|
|
builder.Services.AddCommand<CreateOrderCommand, int, CreateOrderHandler>();
|
|
```
|
|
|
|
## Basic Query
|
|
|
|
```csharp
|
|
public record GetOrderQuery
|
|
{
|
|
public int OrderId { get; init; }
|
|
}
|
|
|
|
public class GetOrderHandler : IQueryHandler<GetOrderQuery, OrderDto>
|
|
{
|
|
public async Task<OrderDto> HandleAsync(GetOrderQuery query, CancellationToken ct)
|
|
{
|
|
// Handle query
|
|
return orderDto;
|
|
}
|
|
}
|
|
|
|
// Registration
|
|
builder.Services.AddQuery<GetOrderQuery, OrderDto, GetOrderHandler>();
|
|
```
|
|
|
|
## See Also
|
|
|
|
- [Samples Overview](README.md)
|