-
-
Save dcomartin/b335f0b24437d58bfb1b4f60e543836b to your computer and use it in GitHub Desktop.
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 Product : Entity, IAggregateRoot | |
{ | |
public string Name { get; private set; } | |
public decimal Price { get; private set; } | |
public Product(string name, decimal price) | |
{ | |
Name = name; | |
Price = price; | |
} | |
public void SetName(string name) | |
{ | |
Name = name; | |
} | |
public void SetPrice(ProductPrice price) | |
{ | |
Price = price; | |
} | |
} | |
public record struct ProductPrice | |
{ | |
private readonly decimal _value; | |
public ProductPrice(decimal value) | |
{ | |
if (value <= 0) | |
{ | |
throw new DomainException("Product price must be greater than zero."); | |
} | |
_value = value; | |
} | |
public static implicit operator decimal(ProductPrice price) | |
{ | |
return price._value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment