fluentvalidation

ViewModel validation for a List

那年仲夏 提交于 2019-11-26 21:29:49
I have the following viewmodel definition public class AccessRequestViewModel { public Request Request { get; private set; } public SelectList Buildings { get; private set; } public List<Person> Persons { get; private set; } } So in my application there must be at least 1 person for an access request. What approach might you use to validate? I don't want this validation to happen in my controller which would be simple to do. Is the only choice a custom validation attribute? Edit: Currently performing this validation with FluentValidation (nice library!) RuleFor(vm => vm.Persons) .Must((vm,

Should I abstract the validation framework from Domain layer?

こ雲淡風輕ζ 提交于 2019-11-26 18:46:28
I am using FluentValidation to validate my service operations. My code looks like: using FluentValidation; IUserService { void Add(User user); } UserService : IUserService { public void Add(User user) { new UserValidator().ValidateAndThrow(user); userRepository.Save(user); } } UserValidator implements FluentValidation.AbstractValidator. DDD says that domain layer have to be technology independent. What I am doing is using a validation framework instead of custom exceptions. It's a bad idea to put validation framework in the domain layer? Just like the repository abstraction? Well, I see a few

unobtrusive client validation using fluentvalidation and asp.net mvc LessThanOrEqualTo not firing

北战南征 提交于 2019-11-26 17:53:58
问题 I have the following rules the 1st does work using unobtrusive, client side validation, the second does not any ideas why? RuleFor(x => x.StartDate) .LessThanOrEqualTo(x => x.EndDate.Value) .WithLocalizedMessage(() => CommonRes.Less_Than_Or_Equal_To, filters => CommonRes.Start_Date, filters => CommonRes.End_Date); RuleFor(x => x.StartDate) .GreaterThanOrEqualTo(x => x.AbsoluteStartDate) .LessThanOrEqualTo(x => x.AbsoluteEndDate) .WithLocalizedMessage(() => CommonRes.Between, filters =>

Should I abstract the validation framework from Domain layer?

青春壹個敷衍的年華 提交于 2019-11-26 06:32:29
问题 I am using FluentValidation to validate my service operations. My code looks like: using FluentValidation; IUserService { void Add(User user); } UserService : IUserService { public void Add(User user) { new UserValidator().ValidateAndThrow(user); userRepository.Save(user); } } UserValidator implements FluentValidation.AbstractValidator. DDD says that domain layer have to be technology independent. What I am doing is using a validation framework instead of custom exceptions. It\'s a bad idea