1

I'm working on an app where the following requirements exist:

  • A user submits some data in a form and this gets persisted as a "Draft Copy."
  • On the other end, an approver reads it and takes some action (Approve, Reject, etc)
  • If the approver approves the Draft Copy, it becomes a Contract and the two parties are legally bound. The original submitter can go back and make changes to the Draft Copy, and resubmit. When the approver approves the most recent version, the existing Contract is replaced with this new one.

What I'm struggling with is we are trying to employ DDD on our project and no solution really "feels right." We are all pretty inexperienced with modern DDD, so finding the right model is quite confusing.

This is not a Document Management problem. There is always exactly one Draft Copy which the submitter works with, and sometimes there is a Contract which neither party can edit (edits are performed by resubmitting the Draft Copy with changes). For these purposes, the fields in these two domain concepts are identical.

Is there some design pattern or DDD friendly solution that can be applied here?

4

1 回答 1

2

我不确定你在这里想要什么,但我建议你应该看看EventSourcing模式。它对于跟踪域对象的变化非常有用。关注马丁·福勒:

事件溯源确保对应用程序状态的所有更改都存储为一系列事件。我们不仅可以查询这些事件,还可以使用事件日志来重构过去的状态,并以此为基础自动调整状态以应对追溯变化。

和格雷格杨:

拥有两个模型的另一个问题是它必然需要更多的工作。必须创建代码来保存对象的当前状态,并且必须编写代码来生成和发布事件。不管你如何做这些事情,它不可能比只发布事件更容易,即使你有一些东西可以让存储当前状态变得非常简单,比如文档存储,仍然需要努力将它带入项目中。

——格雷格·杨——

当用户提交“草稿副本”时,应该引发一个事件并将其存储到EventSourcing. 另一个用户提出另一个“草稿副本”将被EventSourcing对象捕获并将其标记为新版本。如何使它与众不同,您应该应用 DDD。文档对象是一个Domain对象并且有一个标识符。

Eventsourcing实体的每个版本中查询和更新状态,并取回对象的版本将很容易。

您可以EventSourcingMSDN获得更多参考。

希望这有帮助。

于 2013-05-20T04:47:11.850 回答