DDD - 表示/应用层脏检查
如果我的应用程序有一个应用程序层,它公开了可以由我的表示层调用的服务,并且这些应用程序服务将域对象(不使用 DTO)返回到表示层,如果用户更改了域对象的状态,我如何确定当用户将其传递回应用层进行更新时,用户更改了哪些内容?
那么应用程序层如何确定 UI 对域对象进行了哪些更改,以便它可以
- 开始工作单元
- 从存储库检索域对象
- 将更改应用到域对象
- 提交工作单元
If my application has an Application Layer which exposes services that can be called by my Presentation Layer and these Application services return domain objects(not using DTOs) to the Presentation Layer, if a user changes the state of the domain object how do I then determine what has been changed by the user when it is passed back down to the Application Layer for updating??
So how does the Application Layer determine what changes that have been made to the domain object by the UI so that it can
- Begin a UnitOfWork
- Retrieve the domain object from repository
- Apply the changes to the domain object
- Commit the UnitOfWork
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您在表示层和“较低”层之间使用应用程序服务,所以您可能使用与 ORM 会话分离的域对象,您可以在表示层中操作它们,然后将它们返回以进行持久化。
真正的问题是你为什么需要这个。通常需要对实体进行脏检查,因为用户在 UI 中更改了实体,因此您需要显示诸如“您确定要离开此表单吗”之类的消息。
无论哪种方式,我建议您研究一下您正在开发的 UI 框架上的数据绑定机制(WinForms / WPF?)。您可以让您的实体实现类似 INotifyPropertyChanged 接口的东西。您可以让 UI 中的演示者侦听此更改,并将当前编辑的实体标记为脏。您可以为包含 IsDirty 属性的实体创建一个基类。这完全取决于您想要在哪里以及做什么......
Because you are using application services between presentation and "lower" layers, you probably use domain objects that are detached from the ORM session, you manipulate them in presentation, and return them back for persistence.
Real question is why do you need this. Usually dirty checking of entity is needed because user changes it in the UI, so you need to display messages like "Are you sure you want to leave this form" or something like that.
Either way, I suggest you look into databinding mechanisms on the UI frameworkyou are working on (WinForms / WPF ? ). You can have your entities implement something like INotifyPropertyChanged interface. You can have your presenter in UI listening for this change, and marking the current edited entity as dirty. You can have a base class for your entities containing IsDirty property. It all depends on where and what are you trying to do...