类型 'FluentValidation.IValidator' 不是开放泛型 class
The type 'FluentValidation.IValidator' is not an open generic class
我正在注册 ASP.NET 核心应用程序
services.Scan(x => x.FromAssembliesOf(typeof(Startup))
.AddClasses(y => y.AssignableTo(typeof(IValidator)))
.AsImplementedInterfaces()
.WithScopedLifetime());
我尝试使用 Autofac 复制它,所以我使用了:
builder
.RegisterAssemblyTypes(typeof(Startup).Assembly)
.AsClosedTypesOf(typeof(IValidator))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
但是我得到了以下错误:
Unhandled Exception: System.ArgumentException:
The type 'FluentValidation.IValidator' is not an open generic class or interface type so it won't work with methods that act on open generics.
我做错了什么?
而不是 AsClosedTypesOf
使用 Where
子句来过滤和注册实现 IValidator
的类型。 AsClosedTypesOf
专门用于支持开放泛型。 There are plenty of examples in the Autofac docs to help you out.
我正在注册 ASP.NET 核心应用程序
services.Scan(x => x.FromAssembliesOf(typeof(Startup))
.AddClasses(y => y.AssignableTo(typeof(IValidator)))
.AsImplementedInterfaces()
.WithScopedLifetime());
我尝试使用 Autofac 复制它,所以我使用了:
builder
.RegisterAssemblyTypes(typeof(Startup).Assembly)
.AsClosedTypesOf(typeof(IValidator))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
但是我得到了以下错误:
Unhandled Exception: System.ArgumentException:
The type 'FluentValidation.IValidator' is not an open generic class or interface type so it won't work with methods that act on open generics.
我做错了什么?
而不是 AsClosedTypesOf
使用 Where
子句来过滤和注册实现 IValidator
的类型。 AsClosedTypesOf
专门用于支持开放泛型。 There are plenty of examples in the Autofac docs to help you out.