如何确定组件是否可以从IHandlersFilter实现中解析 [英] How to determine if a component is resolvable from an IHandlersFilter implementation
问题描述
我正在尝试编写Castle Windsor v3 IHandlersFilter实现,该实现将滤除无法解决的处理程序。这是为了有选择地还原ResolveAll(如何在Castle 3中恢复为旧的CollectionResolver行为?)
I am trying to write a Castle Windsor v3 IHandlersFilter implementation that will filter out handlers that cannot be resolved. This is in an effort to optionally restore the old (pre-castle 3) behavior of ResolveAll (How to revert to old CollectionResolver behavior in Castle 3?)
我的问题是,从SelectHandlers方法中,什么是确定哪些输入IHandler是可解析的最佳方法(如果有)?我已经使用IHandler.CanResolve方法进行了实验,但是它所使用的参数比我通常处理的要先进一些,因此我不确定如何正确使用该方法。
My question is, from the SelectHandlers method, what is the best way (if any) to determine which of the input IHandlers are resolvable? I have experimented with the IHandler.CanResolve method, but it takes parameters that are a bit more advanced than I typically deal with, so I'm not sure how to use the method properly.
推荐答案
您可以检查 handler.CurrentState == HandlerState.Valid
但是请注意,这是基于Windsor可以静态确定的,因此,答案可能并不总是100%准确(例如,某些组件可能具有动态依赖关系,因此它们在此处显示为无法解决,但是您可以在尝试时成功解决这些问题。)
However be aware this is based on what Windsor can determine statically, therefore the answer may not always be 100% accurate (for example some components may have dynamic dependencies, so they will appear as unresolvable here, yet you'll be able to successfully resolve them when you try).
这篇关于如何确定组件是否可以从IHandlersFilter实现中解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!