1
I’m learning about CQRS and in a Hangout promoted by a Micrososft MVP he presented an implementation of Command
where the model data are validated within the validation of the Command
. Date validations or if there are blank mandatory fields, for example, were not in the model making the model entity almost anemic. Then came the doubts, that despite the MVP’s explanation that for me was not very convincing.
It is really good practice to implement model validation within the validation of the Command
?
Example of the approach used in Hungout:
public abstract class UserCommand : Command
{
public Guid Id { get; protected set; }
public string Name { get; protected set; }
public string Email { get; protected set; }
public DateTime BirthDate { get; protected set; }
}
public class RegisterNewUserCommand : UserCommand
{
public RegisterNewUserCommand(string name, string email, DateTime birthDate)
{
Name = name;
Email = email;
BirthDate = birthDate;
}
public override bool IsValid()
{
ValidationResult = new RegisterNewUserCommandValidation().Validate(this);
return ValidationResult.IsValid;
}
}
public class RegisterNewUserCommand : UserCommand
{
public class RegisterNewUserCommandValidation : UserValidation<RegisterNewUserCommand>
{
public RegisterNewUserCommandValidation()
{
ValidateName();
ValidateBirthDate();
ValidateEmail();
}
}
What is actually done within the validation of a COMMAND
?
Permission for the execution of Command
, existence of duplicity would be an example of validation ?
You can give more details?
– Maniero
@Maniero add snippets of code that exemplify the issue...
– JcSaint