Reputation: 1271
I am using SpecExpress for command validation.(Command validation validates the command before goes to a controller.)
For a simple case I just validated the length, is required or not, regular expressions etc. but now the situation is like that below:
Check a command property eg. "UserName" is it in my database or not, for this scenario, using the repository and check the data in the database or not, if exists then failed or success.
this.Check(ur => ur.UserName).Required().Expect(
(x, y) =>
{
var isExists = userService.isExists(x.UserName);
return !isExists;
},
"User already exist");
My question is that, is it best practice to do data validation inside a command validation?
Or I just do it in a conventional way like in controller or service we check the user is in database or not then move to next step or throw exception.
Upvotes: 0
Views: 91
Reputation: 21
We(my team) do normal validation check at command validation and all type of data validation goes to controller or service.
Upvotes: 1