Skip to content

Server Validation

damiancosmoschapman edited this page Oct 5, 2021 · 2 revisions

Home / Developer / Server Tier / Validation

Description of Server Side Validation, using **Fluent Validation **as a validation framework with code example for creating the Validator.

Summary.

PDF-API uses FluentValidation as a validation framework. For details, please see https://fluentvalidation.net/. The FluentValidation Validators are part of the BaseTemplate model - a relevant validator must be injected into the Base class during construction.

Creating the Validator.

The Validator is applied to a specific DTO. Therefore your DTO must be defined before creating the validator. An example of a validator is shown below:

internal class Comment_VLD : AbstractValidator<Comment_DTO>
{
    internal Comment_VLD()
    {
        //Mandatory - CmmValue
        RuleFor(f => f.CmmValue).Length(1, 1024).WithMessage("Invalid Comment").WithName("CommentValueValidation");
    }
}
Clone this wiki locally