Skip to content

Instantly share code, notes, and snippets.

@offpepe
Created February 25, 2022 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save offpepe/d99ab3c94480ada18b43f090563d02ef to your computer and use it in GitHub Desktop.
Save offpepe/d99ab3c94480ada18b43f090563d02ef to your computer and use it in GitHub Desktop.
Abstract validator example to viewModel/DTO validation
public class CustomValidation : AbstractValidator<ToValidateViewModel>
{
public EditarCursoValidation()
{
RuleFor(example => example).SetValidator(new Validator());
}
}
public class Validator : AbstractValidator<ToValidateViewModel>
{
public Validator()
{
RuleFor(c => c.Property)
.NotNull().WithMessage(ValidationErrorMessage)
.NotEmpty().WithMessage(ValidationErrorMessage);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment