-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Description
It would be nice if this whole process could be like a pluggable pipeline (kind of like middleware) where I can just slot in additional functionality. So initial example would just be to add a fluent validator based on each db model and use attributes like [Required] or [MaxLength(500)] to hint to the validation rules that will apply for that object.
public class MyClass
{
[Required]
public string Name { get; set; }
[MaxLength(500)]
public string Description { get; set; }
}
public class MyClassValidator : AbstractValidator<MyClass>
{
public MyClassValidator()
{
RuleFor(request => request.Name)
.Must(x => !string.IsNullOrWhiteSpace(x))
.WithMessage(x => "Name is required!");
RuleFor(request => request.Description)
.MaximumLength(500)
.WithMessage(x => "Description must be less than 500 characters!");
}
}
Metadata
Metadata
Assignees
Labels
No labels