我在多个程序集中包含FluentValidators。在FluentValidation的早期版本中,我可以这样注册:
services.AddMvc()
.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<ClassInAssemblyOne>())
.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<ClassInAssemblyTwo>());
Run Code Online (Sandbox Code Playgroud)
但是,这现在导致以下错误:
Exception thrown: 'System.InvalidOperationException' in System.Linq.dll
An exception of type 'System.InvalidOperationException' occurred in System.Linq.dll but was not handled in user code
Sequence contains more than one matching element
Run Code Online (Sandbox Code Playgroud)
不再允许了吗?如果没有,执行此操作的正确方法是什么?
将FluentValidation.AspNetCore从7.2.1 升级到7.4.0(以及升级到ASP.NET Core 2.0)后,我遇到了同样的错误。
我只打了.AddFluentValidaton(...)一次电话就解决了,就像这样:
services.AddMvc()
.AddFluentValidation(fv => {
fv.RegisterValidatorsFromAssemblyContaining<ClassInAssemblyOne>());
fv.RegisterValidatorsFromAssemblyContaining<ClassInAssemblyTwo>());
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1159 次 |
| 最近记录: |