Skip to content

Instantly share code, notes, and snippets.

@yreynhout
Created October 31, 2010 10:09
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 yreynhout/656386 to your computer and use it in GitHub Desktop.
Save yreynhout/656386 to your computer and use it in GitHub Desktop.
Guard members
public class Order : Aggregate {
public Order Place(Customer customer, ...) {
customer.GuardPlaceOrder();
//...
}
}
public class Customer Aggregate {
private bool _hasMoreThanFiveOutstandingInvoices;
internal void GuardPlaceOrder() {
//The kind of rule(s) that go in here might change over time.
Guard.Against(_hasMoreThanFiveOutstandingInvoices, PlaceOrderErrorCode.CustomerHasMoreThanFiveOutstandingInvoices);
}
}
public static class Guard {
public static void Against<TErrorCode>(bool assertion, TErrorCode errorCode) where TErrorCode : IConvertible {
if(assertion) throw new OperationException<TErrorCode>(errorCode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment