Last active
August 29, 2015 14:13
-
-
Save mat-mcloughlin/fa8a26eec6ae384e3b4e to your computer and use it in GitHub Desktop.
Sample
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 class SubmitOrder | |
{ | |
public SubmitOrder(int orderId) | |
{ | |
OrderId = orderId; | |
} | |
public int OrderId { get; private set; } | |
} | |
public class SubmitOrderHandler : IHandler<SubmitOrder> | |
{ | |
private IOrderRepository _orderRepository; | |
public SubmitOrderHandler(IOrderRepository orderRepository) | |
{ | |
_orderRepository = orderRepository; | |
} | |
public void Execute(SubmitOrder command) | |
{ | |
var order = orderRepository.Get(command.OrderId); | |
order.Submit(); | |
orderRepository.Update(order); | |
} | |
} | |
public class Order | |
{ | |
public int Id { get; private set; } | |
public string Supplier { get; private set; } | |
public string Status { get; private set; } | |
public void Submit() | |
{ | |
if (Status == "Not Submitted" && Supplier != null) | |
{ | |
Status = "Submitted"; | |
} | |
} | |
} | |
public class Program | |
{ | |
private static dispatcher = new MessageDispatcher(); | |
public static void Main() | |
{ | |
var command = new SubmitOrder(999); | |
// Command dispatcher that binds it to the correct handler | |
dispatcher.Dispatch(command); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment