官方文档:https://fluentvalidation.net/
一、安装:
二、应用:
1、建立PostValidator:
??public class PostValidator:AbstractValidator<PostDTO> ???{ ???????public PostValidator() ???????{ ???????????RuleFor(x => x.Author).NotEmpty() ???????????????.WithName("作者").WithMessage("{PropertyName}是必须填写的") ???????????????.MaximumLength(50).WithMessage("{PropertyName}的最大长度是{MaxLength}"); ???????} ???}
2、aspnetcore注册:
services.AddTransient<IValidator<PostDTO>, PostValidator>();
参考资料:https://v.qq.com/x/page/z0763a2x3j5.html
ASP NET Core ---FluentValidation
原文地址:https://www.cnblogs.com/fuyouchen/p/9588987.html