Skip to content

Validation layer #61

@ScottKane

Description

@ScottKane

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions