我是DDD的新手,所以請原諒我,如果我沒有正確使用這些條款。域名驅動設計問題
我使用C#MS/SQL和NHibernate。
我有一個班級電話付款,這個付款有一個PaymentCurrency,這些都是數據庫中的一個實體。
好的。在我的域模型我希望能夠創建付款爲要麼
Payment p = new Payment(100) // automatically uses the default currency (defined in the db)
或
Payment p = new Payment(100, Repository.GetCurrency("JPY")) // uses Yen defined in the db.
但在我看來,爲了初始化我的域對象與dfault貨幣,我需要污染具有持久性知識的領域模型。即在我可以完成默認付款構造函數之前,我需要從數據庫中加載默認付款對象。
我想象的構造是服用點像
public Payment(int amount) {
Currency = Repository.LoadDefaultCurrency(); // of cource defualt currency would be a singleton
}
public Payment(int amount, Currency c) {
Currency = c; // this is OK since c is passed in from outside the domain model.
}
謝謝你的建議。
-1 from me - 我相信還有另一種獲取貨幣信息的方法,而不必訴諸於持久性或依賴注入。 – duffymo 2009-12-12 14:07:57