Skip to content

Instantly share code, notes, and snippets.

@darjanbogdan
Last active July 2, 2020 23:46
Command & Query Domain - Data Validation - Custom Validator
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