小编Ste*_*ios的帖子

在DDD中,viewmodel如何重用领域模型行为?

我不确定,但只要我读到有关 ddd 的内容,域模型就永远不应该离开应用程序层..如果这是真的,那么视图模型如何重用域模型的行为?

从 ddd 角度假设以下发票模型

  public class Invoice
{
    public int Id { get; set; }

    public int CustomerID { get; internal set; }

    public void ChangeCustomer(Customer customer)
    {
        if (customer.IsActive == false)
            throw new Exception("Inactive customers cannot be used");

        CustomerID = customer.Id;
        //other properties change also that need to be reflected to the user interface
    }
}
Run Code Online (Sandbox Code Playgroud)

现在让发票 ViewModel 尝试 #1。按照这个想法,我在重用域行为方面没有问题,但域层必须引用本例中的 UI 项目(WPF)。但在这里我担心我们不应该在应用程序层之外使用域层

 public class InvoiceVMOption1 : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyUI(string PropertyName)
    { …
Run Code Online (Sandbox Code Playgroud)

c# wpf domain-driven-design behavior viewmodel

2
推荐指数
1
解决办法
1029
查看次数

标签 统计

behavior ×1

c# ×1

domain-driven-design ×1

viewmodel ×1

wpf ×1