Created
September 7, 2018 03:48
-
-
Save thangchung/c8a63e99eb2703666962e6f895f52791 to your computer and use it in GitHub Desktop.
Clean Domain-driven Design article
This file contains hidden or 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 sealed class Product : IdentityBase | |
| { | |
| private Product() : base() | |
| { | |
| } | |
| private Product(Guid productId) | |
| : this(productId, string.Empty, 0.0D, string.Empty) | |
| { | |
| } | |
| private Product(Guid productId, string name, double price, string desc) | |
| : this(GenerateId(), productId, name, price, desc) | |
| { | |
| } | |
| private Product(Guid id, Guid productId, string name, double price, string desc) | |
| { | |
| Id = id; | |
| ProductId = productId; | |
| Name = name; | |
| Price = price; | |
| Desc = desc; | |
| } | |
| public static Product Load(Guid productId) | |
| { | |
| return new Product(productId); | |
| } | |
| public static Product Load(Guid productId, string name, double price, string desc) | |
| { | |
| return new Product(productId, name, price, desc); | |
| } | |
| public Guid ProductId { get; private set; } | |
| [NotMapped] public string Name { get; private set; } | |
| [NotMapped] public double Price { get; private set; } | |
| [NotMapped] public string Desc { get; private set; } | |
| public CartItem CartItem { get; private set; } | |
| public Product LinkCartItem(CartItem cartItem) | |
| { | |
| CartItem = cartItem; | |
| return this; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment