C# 使用';其中';谓语
我对如何实施符合以下条件的注册感到困惑:C# 使用';其中';谓语,c#,.net,dependency-injection,castle-windsor,ioc-container,C#,.net,Dependency Injection,Castle Windsor,Ioc Container,我对如何实施符合以下条件的注册感到困惑: 从当前程序集 公共+非公共类型 与TInterface相同的命名空间 所有服务和自助服务 类型应以“适配器”结尾 我使用以下方法,但我不理解where put'where'类型是子句: private BasedOnDescriptor CreateDescriptor<TInterface>(Predicate<Type> accepted) { return Classes .FromAssemblyCon
private BasedOnDescriptor CreateDescriptor<TInterface>(Predicate<Type> accepted)
{
return Classes
.FromAssemblyContaining<TInterface>()
.IncludeNonPublicTypes()
.Where(Component.IsInSameNamespaceAs<TInterface>())
.WithService.AllInterfaces()
.WithService.Self();
}
private BasedOnDescriptor CreateDescriptor(接受谓词)
{
返回类
.FromAssemblyContaining()
.includeNoPublicTypes()
.Where(Component.IsInSameNamespaceAs())
.WithService.AllInterfaces()
.WithService.Self();
}
“accepted”子句应指出应使用的类型名称
谢谢。.If(t=>t.Name.EndsWith(“适配器”))
但是,抛开如何操作不谈,为了架构的清晰性,最好将这些类型分离到它们自己的名称空间中。副作用是,您不需要额外的筛选器谓词。谢谢!这些类型确实在同一个名称空间中,但名称空间包含一些其他类型,此外,我不拥有这些类型,因为它们是自动生成的,并且来自ado.net)。奇怪的是,“where”和“if”之间有不同的语义。如果“where”能够流畅地进行链式配置,这将是透明的。我可以为BasedOnDescriptor使用OnCreate吗?@Dmitry
.Configure(x=>x.OnCreate())
这个BasedOnDescriptor的“OnCreate”有一个签名:OnCreate(params Action[]actions)为什么我必须在使用这个“Configure”之前过滤所有适配器。谢谢你的回复。