Use this file to discover all available pages before exploring further.
The Intent.DomainServices module generates domain services that encapsulate business logic that doesn’t naturally fit within a single entity or value object.
public interface IOrderValidationService{ ValidationResult ValidateOrder(Order order, Customer customer);}public class OrderValidationService : IOrderValidationService{ public ValidationResult ValidateOrder(Order order, Customer customer) { var result = new ValidationResult(); // Validate customer credit if (customer.CreditLimit < customer.CurrentCredit + order.Total) { result.AddError("Customer credit limit exceeded"); } // Validate order items if (!order.Items.Any()) { result.AddError("Order must contain at least one item"); } // Validate minimum order amount if (order.Total < 10) { result.AddError("Order total must be at least $10"); } // Validate delivery address if (order.ShippingAddress == null) { result.AddError("Shipping address is required"); } else if (!IsDeliverableAddress(order.ShippingAddress)) { result.AddError("Cannot deliver to specified address"); } return result; } private bool IsDeliverableAddress(Address address) { // Check if address is in serviceable area return true; // Simplified }}public class ValidationResult{ private readonly List<string> _errors = new(); public bool IsValid => !_errors.Any(); public IReadOnlyList<string> Errors => _errors.AsReadOnly(); public void AddError(string error) { _errors.Add(error); }}
public class Order{ public void CalculateTotal(IPricingService pricingService) { Total = pricingService.CalculateOrderTotal(this); if (pricingService.IsEligibleForFreeShipping(this, ShippingAddress)) { ShippingCost = 0; } } public bool Validate(IOrderValidationService validationService, Customer customer) { var result = validationService.ValidateOrder(this, customer); return result.IsValid; }}
public class PricingServiceTests{ [Fact] public void ApplyDiscount_VIPCustomer_Returns10PercentOff() { // Arrange var service = new PricingService(); var customer = new Customer("John", "john@example.com") { IsVIP = true }; var amount = 100m; // Act var result = service.ApplyDiscount(amount, customer); // Assert Assert.Equal(90m, result); } [Fact] public void IsEligibleForFreeShipping_OrderOver50_ReturnsTrue() { // Arrange var service = new PricingService(); var order = new Order { Total = 60m }; var address = new Address("123 Main St", "City", "12345"); // Act var result = service.IsEligibleForFreeShipping(order, address); // Assert Assert.True(result); }}