CQRS验证和独特性 [英] CQRS Validation & uniqueness

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

问题描述

在CQRS体系结构中,我想验证当我发送InsertSettingCommand(设置是键/值对象)时,我想检查该键在数据库中是否不存在。如果我了解CQRS&验证很好,它说只有在验证某些格式设置(例如检查电子邮件是否符合某种语法或客户的名字不为空)时,才应在客户端执行验证。但就我而言,我需要查询数据库以查看其是否存在,但是我不知道在客户端查询我的读取存储是否正确?还是应该在我的域侧调用我的读取存储区?然后抛出一个InsertSettingDuplicated事件?

In my CQRS architecture, I'd like to validate that when I send a InsertSettingCommand (setting is a key/value object), I want to check that the key doesn't already exist in my database. If I understand CQRS & validation well, it says that the validation should be performed in client side only when it's about verifying some formatting stuffs like checking that email respects some syntax or that customer's name is not empty. But in my case, I need to query my database to see if it exists, but I don't know if it's correct to query my read store in client-side ? Or should I call my read store in my domain side ? Then throws an InsertSettingDuplicated event ?

那么,在CQRS环境中,我遇到的最佳选择是什么?有人在谈论补偿行为吗?

So what's the best approch to take in my situation in a CQRS environment? Some people talk about compensating actions ? Is it something that can helps me ?

谢谢。

推荐答案


  1. 如果需要修复一些错误的命令,这些命令会破坏您的读/写存储,请使用补偿操作。

  2. 无疑,在发送命令之前使用读取存储来验证某些内容是毫无疑问的,以便发送有效命令。

这篇关于CQRS验证和独特性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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