比如我有兩個驗證規則驗證:如何重用數據FluentValidation
// Rule 1
RuleFor(o => o.Email).Must((email) => this.GetDataDataFromDB(email) != 0)
.WithMessage("User with provided Email was not found in database!");
// Rule 2
RuleFor(o => o.Email).Must((email) => this.GetDataDataFromDB(email) >= 1)
.WithMessage("There are multiple users with provided Email in database!");
正如你可以看到有兩個調用具有相同的方法的數據庫。我該如何調用它並重用其他規則的數據?
RuleFor(o => o.Email).Must((email) => this.GetDataDataFromDB(email) >= 1)
.WithMessage("There are multiple users with following Email '{0}' in database!",
(model, email) => { return email; });
有沒有更好的方式來顯示錯誤消息,不是所有的時間寫的lambda表達式以檢索屬性:顯示錯誤消息時
另一個問題?就像在某處保存模型一樣,然後再使用它。
簡單易用的解決方案將會很棒!
RuleFor(O => o.Email)。必須((電子郵件)=> this.GetDataDataFromDB(電子郵件)<= 1)的條件<=不符合驗證消息的含義 –