Domain entity representing a customer's basket with basket items; ensures valid ID and non-empty items, and supports replacing all items via Update.
[method: JsonConstructor]
public sealed class CustomerBasket() : AuditableEntity<string>
{
private readonly List<BasketItem> _basketItems = [];
public CustomerBasket(
[StringSyntax(StringSyntaxAttribute.GuidFormat)] string id,
IReadOnlyList<BasketItem> items
)
: this()
{
Id = id ?? throw new BasketDomainException("Customer ID cannot be null.");
_basketItems =
items.Count > 0
? [.. items]
: throw new BasketDomainException("Basket must contain at least one item.");
}
public IReadOnlyCollection<BasketItem> Items => _basketItems.AsReadOnly();
/// <summary>
/// Updates the customer basket by replacing all existing items with the provided items.
/// </summary>
/// <p
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key