Skip to content

Instantly share code, notes, and snippets.

@mat-mcloughlin
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mat-mcloughlin/fa8a26eec6ae384e3b4e to your computer and use it in GitHub Desktop.
Save mat-mcloughlin/fa8a26eec6ae384e3b4e to your computer and use it in GitHub Desktop.
Sample
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