待更新模块 - 域实体或值对象? [英] Pending Updates Module - Domain Entity or Value Object?

查看:141
本文介绍了待更新模块 - 域实体或值对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个过程中大量传统的ASP Web应用程序转换为ASP.Net MVC与领域驱动设计。虽然很多我的域名与DDD非常适合,我一直运行到的情况下纯DDD的做法是不恰当的。例如我的应用程序的读取端和写边显著变化。没问题,我创建了一个单独的读模式,并实施CQRS的简化版本(任何情况下的采购,没有单独的DB)。另一个问题是,大部分的数据库操作。没问题,正被实现为服务。这是我目前的窘境。我们的系统使用户可以更改系统是在将来的某一天生效。为了适应这一点,我们有一个存储挂起更改,直至生效日期的数据库表。在生效日期,自动任务运行,并执行实际的数据库更新。更新任务可以包括域逻辑,使部分与DDD配合并且是没有问题的。为了显示是怎么回事,这里是处理未决的更新类:

I am in the process converting a large classic ASP web application to ASP.Net MVC with domain driven design. While much of my domain fits well with DDD, I keep running into situations where a pure DDD approach is not appropriate. For example the read side of my application varies significantly from the write side. No problem, I created a separate read model, and implemented a simplified version of CQRS (no event sourcing, no separate db). Another issue was bulk database operations. No problem, that is being implemented as a service. Here's my current quandary. Our system allows users to make changes to the system that are effective on some future date. To accommodate this we have a database table that stores the pending changes until the effective date. On the effective date, an automated task runs and performs the actual database updates. The update task can include domain logic, so that part fits with DDD and is not a problem. To help visualize what is going on, here is the class that handles the pending update:

public class PendingChanges
{
    public int EntityID {get; set;}
    public string FromTable {get; set;}
    public string DetailField {get; set;}
    public string NewValue {get; set;}
    public DateTime EffectiveDate {get; set;}
    public DateTime EnteredDate {get; set;}
    public int UserID {get; set;}
    public string UserName {get; set;}
    public string UserArea { get; set; } 

   // Business logic and validation here? 
} 

正如你可以看到这是一个通用类,它可以处理更新各种数据库表。它基本上存储在数据库的列正在更新,新的值,该列将是,它是属于在该表中,有效日期和一些记录数据。

As you can see this is a generic class that can handle updates to various database tables. It basically stores the database column that is being updated, the new value that the column will be, the table that it belongs in, the effective date and some logging data.

因此​​,这里是我的问题:应该收集的待定更新表中的待处理的更新并将其存储在逻辑建模为一个域对象还是应该处理一些其他的方式,例如,作为一个服务

So here are my questions: Should the logic that collects the pending update and stores it in the pending updates table be modeled as a domain object or should it be handled some other way, for example as a service?

要换个说法就是PendingChanges本身自己的域逻辑域实体?有适用于PendingChanges从该变化正在发生在实体上不同的一些业务规则。例如什么是UserArea可以被认为是业务规则的将是FromTable验证合法的值,就更不用说了。

To put it another way is PendingChanges itself a domain entity with its own domain logic? There are some business rules that apply to PendingChanges as distinct from the entities that the changes are taking place on. For example what constitutes a UserArea could be considered a business rule as would be legal values for FromTable, not to mention validation.

或者是PendingChanges值对象,因为它是在不同的域对象的可重用?如果这是它让使用PendingUpdatesService更有意义了呢?

Or is PendingChanges a value object since it is reusable across different domain objects? If that is the case does it make more sense to use PendingUpdatesService?

推荐答案

是域的一部分,做数据库更新即你建立的数据库管理/报告软件的概念?如果PendingChanges有你的域名意义,那么也许是一个实体,尽管这种技术性事项少,得到适当的领域建模则显得更为重要。如果PendingChanges是你的应用程序使用,以更新DB(域)的东西一类,那么它无关,与DDD,也不符合您的域。这是你的基础设施的一部分。良好的面向对象仍然需要,虽然,但没有DDD流行语在这里。

Is part of the Domain the concept of doing db updates i.e are you building database management/reporting software? If PendingChanges has a meaning for your Domain then maybe is an entity, although this technicality matters less, getting the proper domain modelling is much more important. If PendingChanges is a class that your app is using to update (domain)things in the db, then it has nothing to do with DDD nor with your domain. It is a part of your infrastructure. Good OOP is still needed though, but no DDD buzzwords here.

顺便说一下,如果一个对象有一个id,它通常是一个实体。

Btw, if an object has an id, it usually is an Entity.

这篇关于待更新模块 - 域实体或值对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆