Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arleypadua/5675987e7f497f4d9396f8f495a53b8c to your computer and use it in GitHub Desktop.
Save arleypadua/5675987e7f497f4d9396f8f495a53b8c to your computer and use it in GitHub Desktop.
anemic-domain-model-encapsulated-constructor
public static Order New(string orderId, string customerId, DateTime? creationTime = null)
{
if (string.IsNullOrWhiteSpace(orderId)) throw new ArgumentNullException(nameof(orderId));
if (string.IsNullOrWhiteSpace(customerId)) throw new ArgumentNullException(nameof(customerId));
return new Order
{
OrderId = orderId,
CustomerId = customerId,
CreationTime = creationTime ?? DateTime.UtcNow,
Items = new List<OrderItem>()
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment