Ayo*_*aye 2 c# fluentvalidation asp.net-web-api asp.net-core
在 ASP.NET Core-6 Web API 中,我使用 FluentValidation.AspNetCore(11.2.1)。
我在 Program.cs 中有这段代码:
builder.Services.AddMvc().AddFluentValidation(fv => {
fv.DisableDataAnnotationsValidation = true;
fv.RegisterValidatorsFromAssembly(typeof(Program).Assembly);
fv.RegisterValidatorsFromAssembly(Assembly.GetExecutingAssembly());
fv.ImplicitlyValidateChildProperties = true;
fv.ImplicitlyValidateRootCollectionElements = true;
fv.AutomaticValidationEnabled = true;
});
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误,上面的所有代码都突出显示:
FluentValidationMvcExtensions.AddFluentValidation(IMvcBuilder, Action)' 已过时:'不推荐调用 AddFluentValidation()
我该如何解决这个问题?
谢谢
小智 6
添加以下方法以实现流畅的自动验证。这也将修复过时的警告
builder.Services.AddFluentValidationAutoValidation();
builder.Services.AddFluentValidationClientsideAdapters();
builder.Services.AddValidatorsFromAssembly(typeof(SignUpRequestModelValidator).Assembly);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8712 次 |
| 最近记录: |