在我的域模型中,我有一個名爲「Inventory」的實體。要在庫存中進行某種移動,我需要訪問業務級別配置以進行檢查。DDD - 將配置服務注入到實體中
我在庫存實體
public class Inventory
{
// Some codes, properties and arguments are omitted for brevity.
public int InventoryId { get; set; }
public virtual Product Product { get; set; }
public virtual IList<InventoryTransaction> Transactions { get; set; }
public virtual IList<Stock> Stocks {get; set; }
// ........
public void purchase(double qty, decimal cost) { //....... }
public double QuantitiesOnHand() { //..... }
public decimal CostOfItemsOnHand() { //....... }
// This method require to access certain configuration in order to
// process the sale of item.
public decimal Sell(double qty, decimal cost) { //..... }
}
下面的方法來處理我需要訪問某些配置的銷售。注入配置界面以處理該實體內的銷售是否是一種好的做法。它會損害DDD的純度嗎?或者我應該只將這個'Sell()'方法移動到域服務層?
編輯:
public virtual IList<Stock> Stocks {get; set; }
加入以上的類定義持有股票的特定庫存項目。
爲什麼不將配置值傳遞給銷售方法? –
DomainService爲了簡單起見,或者在損害時重構它。 – Hippoom
@DavinTryon,你是對的。但我有大約3到4個設置,我需要通過。我也懷疑將來它可能會增加。請告訴你的建議。 – BlueBird