I know that keeping large collections in Aggregates impacts performance.
In my use case i have STORE which can have multiple PRODUCT and each product can have CUSTOMIZATION(Not more than 10-20 customization).
I thought of creating one store aggregate only and update product and customization through it but as product collection can be large so it will impact performance. So I have two aggregates STORE(to create store) and PRODUCT(with storeId,all product operation) with this approach I am not able to check if product already exist or not.
what i am doing now is getting all products by StoreId in my handler and checking duplicate which is not right way as it should belong to my domain model.
Anyone has better idea to solve this. below are my domain models.
public class Store : Entity<Guid>, IAggregateRoot
{
private Store()
{
this.Products = new List<Product>();
}
private Store(string name, Address address) : base(System.Guid.NewGuid())
{
this.Name = name;
this.Address = address;
}
private Store(string name, Address address, ContactInfo contact) : this(name, address)
{
this.Contact = contact;
}
public string Name { get; private set; }
public Address Address { get; private set; }
public ContactInfo Contact { get; private set; }
}
public class Product : Entity<Guid>, IAggregateRoot
{
private Product()
{
}
private Product(Guid storeId, ProductInfo productInfo) : base(Guid.NewGuid())
{
this.ProductInfo = productInfo;
this.StoreId = storeId;
this.Customizations = new List<Customization>();
}
private Product(Guid storeId, ProductInfo productInfo, IEnumerable<Customization> customizations) : this(storeId, productInfo)
{
this.Customizations = customizations;
}
public ProductInfo ProductInfo { get; private set; }
private List<Customization> _customizations;
public IEnumerable<Customization> Customizations
{
get
{
return _customizations.AsReadOnly();
}
private set
{
_customizations = (List<Customization>)value;
}
}
public Guid StoreId { get; private set; }
public static Product Create(Guid storeId, ProductInfo productInfo)
{
return new Product(storeId, productInfo);
}
public void UpdateInfo(ProductInfo productInfo)
{
this.ProductInfo = productInfo;
}
public void AddCustomization(Customization customization)
{
this._customizations.Add(customization);
}
public void RemoveCustomization(Customization customization)
{
this._customizations.Remove(customization);
}
}