我正在注册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();
我在做什么错了?
答案 0 :(得分:2)
使用AsClosedTypesOf
子句代替Where
来过滤并仅注册实现IValidator
的类型。 AsClosedTypesOf
专门用于支持开放泛型。 There are plenty of examples in the Autofac docs to help you out.