CQRS中的域查询 [英] Domain queries in CQRS

查看:82
本文介绍了CQRS中的域查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试 CQRS 。我们有一个验证情况,其中CustomerService(域服务)需要知道Customer是否存在。客户的电子邮件地址是唯一的。我们的客户存储库(通用存储库)仅具有Get(id)和Add(customer)。

We are trying out CQRS. We have a validation situation where a CustomerService (domain service) needs to know whether or not a Customer exists. Customers are unique by their email address. Our Customer repository (a generic repository) only has Get(id) and Add(customer). How should the CustomerService find out if the Customer exists?

推荐答案

看看此博客文章:在CQRS体系结构

它解决了这个问题。在CQRS中要解决的问题很复杂。 Bjarte的建议是查询报表数据库中现有的客户电子邮件地址,如果有电子邮件,则向域模型发出补偿命令(例如 CustomerEmailAddressIsNotUniqueCompensatingCommand )找到地址。然后,您可以触发适当的事件,其中可能包括 UndoCustomerCreationEvent

It addresses this very issue. It's a complex issue to deal with in CQRS. What Bjarte is suggesting is to query the reporting database for existing Customer e-mail addresses and issue a Compensating Command (such as CustomerEmailAddressIsNotUniqueCompensatingCommand) back to the Domain Model if an e-mail address was found. You can then fire off appropriate events, which may include an UndoCustomerCreationEvent.

通读以上博客中的评论

Adam D. 建议在评论中,验证是域关注的问题。结果,您可以将ReservedEmailAddresses存储在一项服务中,该服务可以促进客户创建,并被事件存储中的事件所淹没。

Adam D. suggests in a comment that validation is a domain concern. As a result, you can store ReservedEmailAddresses in a service that facilitates customer creation and is hydrated by events in your event store.

我不确定是否有一种简单的解决方案这个感觉完全干净的问题。让我知道您的想法!

I'm not sure there's an easy solution to this problem that feels completely clean. Let me know what you come up with!

祝您好运!

这篇关于CQRS中的域查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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