dotnet --version
Create a .NET solution with Domain, Application, Infrastructure, and API layers following Clean Architecture dependency rules.
1 namespace Domain.Entities; 2 3 public class Product 4 { 5 public Guid Id { get; private set; } 6 public string Name { get; private set; } 7 public Money Price { get; private set; } 8 public DateTime CreatedAt { get; private set; } 9 10 private Product() { } // EF Core constructor 11 12 public static Product Create(string name, decimal amount, string currency) 13 { 14 if (string.IsNullOrWhiteSpace(name)) 15 throw new ArgumentException("Name cannot be empty.", nameof(name)); 16 17 return new Product 18 { 19 Id = Guid.NewGuid(), 20 Name = name, 21 Price = new Money(amount, currency), 22 CreatedAt = DateTime.UtcNow, 23 }; 24 } 25 26 public void UpdatePrice(decimal amount, string currency) 27 { 28 Price = new Money(amount, currency); 29 } 30 } 31 32 public record Money(decimal Amount, string Currency) 33 { 34 public Money 35 { 36 if (Amount < 0) throw new ArgumentException("Amount cannot be negative."); 37 if (string.IsNullOrWhiteSpace(Currency)) throw new ArgumentException("Currency is required."); 38 } 39 } 40
Sign in to share your feedback and join the discussion.