卸下温莎城堡3中的组件 [英] Remove components in Castle Windsor 3

查看:99
本文介绍了卸下温莎城堡3中的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在温莎城堡使用TypedFactoryFacility允许我使用接口工厂依赖注入。

I am using the TypedFactoryFacility in Castle Windsor to allow me to use the interface-factory dependency injection.

我在自动委托工厂注入Func时遇到问题

I am having issues with the automatic delegate-factory injecting Func into automatically resolved components when these are not required (should be Null).

我要保留TypedFactoryFacility,但按照以下问题删除DelegateFactory:

I would like to keep the TypedFactoryFacility, but remove the DelegateFactory, as per this question:

可以

不幸的是,现在无法从温莎城堡(第3版)中删除组件。

Unfortunately there is now no way to remove components from Castle Windsor (version 3).

有人可以建议删除DelegateFactory或以某种方式禁用它的方法,以便它不会将Func注入无法解决的服务中(为什么还要注入它不知道的Func)怎么处理无论如何??

Can someone suggest either a way to remove the DelegateFactory or somehow disable it so it does not inject Func into my services that can not be resolved (why is it even injecting Func that it does not know how to handle anyway??)

推荐答案

我无法找到如何删除组件(应该重新添加)。

I was unable to find how to remove a component (this should be added back in).

我可以找到的禁用DelegateFactory的最佳方法是停止使用TypedFactoryFacility类设置类型工厂,并使用其中的Init函数中的代码减去委托工厂方法

The best way I could find to disable the DelegateFactory was stop using the TypedFactoryFacility class to setup the Typed Factories and use the code from the Init function inside it, minus the delegate factory methods.

因此:

// Stop using AddFacility
//container.AddFacility<TypedFactoryFacility>();

// Initialise the TypedFactoryFacility manually, leaving out the DelegateFactory components.
container.Kernel.Register(new IRegistration[] {
   Component.For<TypedFactoryInterceptor>().NamedAutomatically(TypedFactoryFacility.InterceptorKey),
   // Disable DelegateFactory
   // Component.For<ILazyComponentLoader>().ImplementedBy<DelegateFactory>().NamedAutomatically(TypedFactoryFacility.DelegateFactoryKey),
   Component.For<ITypedFactoryComponentSelector>().ImplementedBy<DefaultTypedFactoryComponentSelector>().NamedAutomatically("Castle.TypedFactory.DefaultInterfaceFactoryComponentSelector"),
   // Disable DelegateFactory
   // Component.For<ITypedFactoryComponentSelector>().ImplementedBy<DefaultDelegateComponentSelector>().NamedAutomatically(TypedFactoryFacility.DefaultDelegateSelectorKey)
});
container.Kernel.ComponentModelBuilder.AddContributor(new TypedFactoryCachingInspector());

我必须使用魔术字符串 Castle.TypedFactory.DefaultInterfaceFactoryComponentSelector DefaultInterfaceSelectorKey 是一个内部字段。

I had to use magic string "Castle.TypedFactory.DefaultInterfaceFactoryComponentSelector" DefaultInterfaceSelectorKey is an internal field.

现在,您可以使用接口工厂,而无需委托-工厂搞砸了一切。

Now you can use interface-factories, without delegate-factories messing everything up.

这篇关于卸下温莎城堡3中的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆