mirror of https://github.com/abpframework/abp
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
					
						
							1.4 KiB
						
					
					
				
			
		
		
	
	
							1.4 KiB
						
					
					
				FluentValidation 集成
ABP验证基础设施是可扩展的. Volo.Abp.FluentValidation NuGet 包扩展了验证系统使其与FluentValidation库一起工作.
安装
建议使用ABP CLI安装包.
使用ABP CLI
在项目(.csproj文件)的文件夹中打开命令行窗口并输入以下命令:
abp add-package Volo.Abp.FluentValidation
手动安装
如果你想手动安装;
- 
添加 Volo.Abp.FluentValidation NuGet包到你的项目: Install-Package Volo.Abp.FluentValidation
- 
添加 AbpFluentValidationModule到你的模块的依赖列表:
[DependsOn(
    //...other dependencies
    typeof(AbpFluentValidationModule) //Add the FluentValidation module
    )]
public class YourModule : AbpModule
{
}
使用 FluentValidation
按照 FluentValidation文档 创建验证器类. 例如:
public class CreateUpdateBookDtoValidator : AbstractValidator<CreateUpdateBookDto>
{
    public CreateUpdateBookDtoValidator()
    {
        RuleFor(x => x.Name).Length(3, 10);
        RuleFor(x => x.Price).ExclusiveBetween(0.0f, 999.0f);
    }
}
ABP会自动找到这个类并在对象验证时与 CreateUpdateBookDto 关联.