/// <summary> ///异步验证 /// </summary> public static async Task DoValidationAsync(IRoleElementRespository roleElementRespository, RoleElement roleElement, string validatorType) { var roleElementValidator = new RoleElementValidator(roleElementRespository); var validatorReresult = await roleElementValidator.DoValidateAsync(roleElement, validatorType); if (!validatorReresult.IsValid) { throw new DomainException(validatorReresult); } }
/// <summary> ///异步验证 /// </summary> public static async Task DoValidationAsync(IRoleElementRespository roleElementRespository, IEnumerable <RoleElement> roleElements, string validatorType) { var roleElementValidator = new RoleElementValidator(roleElementRespository); var domainException = new DomainException(); foreach (var roleElement in roleElements) { var validatorReresult = await roleElementValidator.DoValidateAsync(roleElement, validatorType); if (!validatorReresult.IsValid) { domainException.AddErrors(validatorReresult); } } if (domainException.ValidationErrors.ErrorItems.Any()) { throw domainException; } }