我是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