English 中文(简体)
CQRS的商业规则有效者和指挥手
原标题:Business rule validators and command handler in CQRS

我是科索沃统计局的新鲜事,我很抱着在书写方面(主要)对商业规则的验证感。 我知道,应当根据有效日期(要求外地、缩短时间、有效电子邮件等)和在业务规则/业务领域进行相关的验证。 实际上,也应适用同一客户方验证规则,以控制该领域,因为我们不相信用户。

因此,我们有有效的指挥(ToCustomer先生),指挥员被援引。 这里是我的验证方法。

  1. Create instances of two command validators in the command handler.
  2. First one validates the command data same as client side validation (required field, valid email, etc.)
  3. Second validator validates the data based on logic within the second validator. Something like "is this customer active", or what ever. I know the changing email doesn t fit here but it is not important. Important thing is there is a business validation here.
  4. We look at the ValidationResult returned by the Validator.Validate(ICommand cmd) and we find out there are errors
  5. We will not get a customer from repository to call on the UpdateEmail method on the AR. So what do we do at this point?

Do I throw and exception in the command handler and add these errors there? Do I send the command to error queue or somewhere else? Do I respond with something like Bus.Reply and return error code? If so, what do I do with the error messages? How do I communicate these errors to the user? I know I can email them later but in a web scenario I can send a request id in the command (or use the message id), and poll for response with the request id and display the error messages to user.

赞赏你的指导。

增 编

问题回答

重要的是要知道,指挥员在被派到手后,即予以拒绝。

至少,在触及整体根基之前,你会遇到无法检测到的一致违反。

但是,在实体之外进行的验证也是简单的验证。 不仅说明长度、计数范围、校对等,还可以通过询问或观点,如收集中独一无二,合理地加以确认。 必须记住,涉及已实现的观点的验证很可能是

在一个实体之外进行cannot的验证是您的业务逻辑验证。 这一验证取决于其运行的背景(。 Udi Dahan s Clarification CQRS

Business logic should not be in a separate validation service. It should be in your domain.

此外,我也认为,不应在指挥手里,而应重新检查在调查股进行的验证。 进行这一验证是为了防止出现领域的腐败——如果不在领域之外进行,那么这个领域仍然受制于无效的参数。

利用指挥处理员重复这一验证只是一项公约。 如果其他前端没有发出指挥,那就是一个无用的重复。 如果要达到多方面的目的,就只是选择哪里进行当时必要的重复验证,在这种情况下,我更愿意在这方面处理。

最后,你将需要放弃手里拒绝的指挥。 我在尽可能例外的情况下完成这项工作。





相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签