在ASP.NET Core-6 Web中,我使用的是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;
});但是,上面突出显示的所有代码都出现了这个错误:
)“是过时的:”调用FluentValidationMvcExtensions.AddFluentValidation(IMvcBuilder,()被废弃。
我怎么才能解决这个问题?
谢谢
发布于 2022-08-18 11:33:13
根据文档(https://docs.fluentvalidation.net/en/latest/aspnet.html),不建议使用自动验证。
因此,我建议不要使用自动验证,并删除AddMvc(),因为自动验证适用于AddMvc、https://github.com/FluentValidation/FluentValidation/issues/1377
现在让我们来看看您的问题,假设您正在使用.net6,下面的代码应该可以工作。
using FluentValidation.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddFluentValidation(conf =>
{
conf.RegisterValidatorsFromAssembly(typeof(Program).Assembly);
conf.AutomaticValidationEnabled = false;
});发布于 2022-10-16 18:17:49
为fluent自动验证添加以下方法。这也将修复过时的警告。
builder.Services.AddFluentValidationAutoValidation();
builder.Services.AddFluentValidationClientsideAdapters();
builder.Services.AddValidatorsFromAssembly(typeof(SignUpRequestModelValidator).Assembly);发布于 2022-10-19 22:07:49
我也有一个类似的错误。
尝试fluentValation.AspNetCore包11.1.2及更低版本。
错误解决。
我希望它对你有用
https://stackoverflow.com/questions/73402059
复制相似问题