private async Task DoValidationAsync(Goods goods, string validatorType) { var personValidator = new GoodsValidator(); var validatorReresult = await personValidator.DoValidateAsync(goods, validatorType); if (!validatorReresult.IsValid) { throw new DomainException(validatorReresult); } }
/// <summary> ///异步验证 /// </summary> public static async Task DoValidationAsync(IGoodsRespository goodsRespository, Goods goods, string validatorType) { var goodsValidator = new GoodsValidator(goodsRespository); var validatorReresult = await goodsValidator.DoValidateAsync(goods, validatorType); if (!validatorReresult.IsValid) { throw new DomainException(validatorReresult); } }
/// <summary> ///异步验证 /// </summary> public static async Task DoValidationAsync(IGoodsRespository goodsRespository, IEnumerable <Goods> goodss, string validatorType) { var goodsValidator = new GoodsValidator(goodsRespository); var domainException = new DomainException(); foreach (var goods in goodss) { var validatorReresult = await goodsValidator.DoValidateAsync(goods, validatorType); if (!validatorReresult.IsValid) { domainException.AddErrors(validatorReresult); } } if (domainException.ValidationErrors.ErrorItems.Any()) { throw domainException; } }