Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created September 23, 2020 21:12
Show Gist options
  • Save dcomartin/bd43c445bd01bf5629a627f8a0c542c4 to your computer and use it in GitHub Desktop.
Save dcomartin/bd43c445bd01bf5629a627f8a0c542c4 to your computer and use it in GitHub Desktop.
public class OrdersController : Controller
{
private readonly IAmACommandProcessor _commandProcessor;
public OrdersController(IAmACommandProcessor commandProcessor)
{
_commandProcessor = commandProcessor;
}
[HttpPost("/sales/orders/{orderId:Guid}")]
public IActionResult PlaceOrder([FromRoute]Guid orderId)
{
var request = new PlaceOrder
{
Id = Guid.NewGuid(),
OrderId = orderId,
};
_commandProcessor.Send(request);
return NoContent();
}
}
public class PlaceOrder : ICommand
{
public Guid Id { get; set; }
public Guid OrderId { get; set; }
}
public class PlaceOrderHandler : RequestHandler<PlaceOrder>
{
private readonly IAmACommandProcessor _commandProcessor;
public PlaceOrderHandler(IAmACommandProcessor commandProcessor)
{
_commandProcessor = commandProcessor;
}
public override PlaceOrder Handle(PlaceOrder command)
{
throw new InvalidOperationException();
return base.Handle(command);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment