Last active
July 2, 2020 23:46
Command & Query Domain - Data Validation - Custom Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateUserNameValidator : IValidator<CreateUserCommand> | |
{ | |
public CreateUserNameValidator(/* dependencies */) { } | |
public async ValueTask<Result<bool>> ValidateAsync(CreateUserCommand command, CancellationToken cancellation) | |
{ | |
if (await IsValidName(command.Name)) | |
return true; | |
return new ValidationError(message: "Name is not valid."); | |
} | |
public Task<bool> IsValidName(string name) => // check if name is valid somehow | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment