【发布时间】:2022-11-02 18:49:11
【问题描述】:
我正在尝试为这种情况提出正确的语法:
规则
规则B
以上都是独立的
规则 C- 只有在 RuleS 和 Rule 都通过验证时才会运行。
例子:
用户 ID 存在 (RuleS)
订单 ID 存在(规则)
OrderId 属于 UserId - 依赖于上述两个规则成功的规则
代码示例(即使 UserIdExists 或 OrderIdExists 之一未能通过验证,也无法调用 OrderBelongsToUser):
RuleFor(request => request).NotNull().DependentRules(() =>
{
RuleFor(request => request).CustomAsync(UserIdExists)
RuleFor(request => request).CustomAsync(OrderIdExists)
}).CustomAsync(OrderBelongsToUser);
【问题讨论】:
标签: fluentvalidation