Autofac 类型';FluentValidation.IValidator';不是一个开放的泛型类

Autofac 类型';FluentValidation.IValidator';不是一个开放的泛型类,autofac,fluentvalidation,Autofac,Fluentvalidation,在我正在注册的ASP.NET核心应用程序上 services.Scan(x => x.FromAssembliesOf(typeof(Startup)) .AddClasses(y => y.AssignableTo(typeof(IValidator))) .AsImplementedInterfaces() .WithScopedLifetime()); 我尝试使用Autofac复制此功能,因此我使用: builder .RegisterAssemblyTyp

在我正在注册的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.

我做错了什么?

使用
Where
子句筛选并仅注册实现
IValidator的类型,而不是
AsClosedTypesOf
AsClosedTypesOf
专门用于支持开放泛型

我不确定
AsClosedTypesOf(Type)
的确切功能,但名称(以及您收到的错误)表明它需要一个“开放”的泛型类型,如IList,并注册所有“封闭”类型,如
IList
IList
等。