-
-
Notifications
You must be signed in to change notification settings - Fork 803
Expand file tree
/
Copy pathPlaceOrderCommandHandler.cs
More file actions
23 lines (18 loc) · 886 Bytes
/
PlaceOrderCommandHandler.cs
File metadata and controls
23 lines (18 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using AotExample.OrderService.Commands;
using Mocha.Mediator;
namespace AotExample.OrderService.Handlers;
public sealed class PlaceOrderCommandHandler(ILogger<PlaceOrderCommandHandler> logger)
: ICommandHandler<PlaceOrderCommand, PlaceOrderResult>
{
public ValueTask<PlaceOrderResult> HandleAsync(PlaceOrderCommand command, CancellationToken cancellationToken)
{
var orderId = Guid.NewGuid().ToString("N")[..8];
logger.LogOrderPlaced(orderId, command.Quantity, command.ProductName);
return new ValueTask<PlaceOrderResult>(new PlaceOrderResult { OrderId = orderId });
}
}
internal static partial class Logs
{
[LoggerMessage(Level = LogLevel.Information, Message = "Order {OrderId} placed: {Quantity}x {ProductName}")]
public static partial void LogOrderPlaced(this ILogger logger, string orderId, int quantity, string productName);
}