使用'where'谓词从Windsor Castle中的Assembly注册类型

Dmi*_*kov 2 .net c# dependency-injection castle-windsor ioc-container

我很困惑如何实现满足以下条件的注册:

  1. 从目前的装配
  2. 公共+非公共类型
  3. 与TInterface相同的命名空间
  4. 所有服务和自我
  5. 该类型应以'适配器'结尾

我使用以下方法,但我不明白把'where'类型的子句放在哪里:

private BasedOnDescriptor CreateDescriptor<TInterface>(Predicate<Type> accepted)
{
   return Classes
       .FromAssemblyContaining<TInterface>()
       .IncludeNonPublicTypes()
       .Where(Component.IsInSameNamespaceAs<TInterface>())
       .WithService.AllInterfaces()
       .WithService.Self();
}
Run Code Online (Sandbox Code Playgroud)

'accepted'子句应该指出应该使用什么类型的名称谢谢.

Krz*_*mic 5

.If(t => t.Name.EndsWith("Adapter"))

然而,把如何不谈,它可能是类型分成自己的命名空间,用于建筑的清晰度是一个好主意.副作用是,你不需要额外的过滤谓词.