'FluentValidation.IValidator'类型不是开放的通用类

时间:2018-08-29 19:38:12

标签: autofac fluentvalidation

我正在注册ASP.NET Core应用程序

$projects_ids = request()->get('projects');
$items = collect($projects_ids);

$fields = $items->map(function ($ids){
   return '?';
})->implode(',');


$projects = Project::orderbyRaw("FIELD (id, ".$fields.")", $items->prepend('id'))
        ->find($projects_ids);

我试图使用Autofac复制它,所以我使用了:

services.Scan(x => x.FromAssembliesOf(typeof(Startup))
  .AddClasses(y => y.AssignableTo(typeof(IValidator)))
  .AsImplementedInterfaces()
  .WithScopedLifetime()); 

但是我遇到了以下错误:

builder
  .RegisterAssemblyTypes(typeof(Startup).Assembly)
  .AsClosedTypesOf(typeof(IValidator))
  .AsImplementedInterfaces()
  .InstancePerLifetimeScope();

我在做什么错了?

1 个答案:

答案 0 :(得分:2)

使用AsClosedTypesOf子句代替Where来过滤并仅注册实现IValidator的类型。 AsClosedTypesOf专门用于支持开放泛型。 There are plenty of examples in the Autofac docs to help you out.

相关问题