开发者

Check for Windsor Container Component Instance

开发者 https://www.devze.com 2023-01-03 02:35 出处:网络
How can I use my Windsor container to check if an instance (not just a component) has been registered?

How can I use my Windsor container to check if an instance (not just a component) has been registered?

i.e. container.ContainsInstan开发者_JS百科ce(typeof(MyType))

[EDIT]

Another way of writing this might be

Kernel.GetAssignableHandlers(typeof(object))
    .Where(handler => handler.Service == typeof(MyType) || handler.ComponentModel.Implementation == typeof(MyType))
    .Any(handler => handler.***Instance*** != null)

Note that the property Instance doesn't exist in the API.


Officially there's no way to check that. The container is completely unaware of activation mechanism used to construct the instance, and it's a good thing.

Unofficially if you don't care about depending on... non-official solution, you can check if components activator is of type (from the top of my head) ExternalInstanceActivator. If it is, than the component has instance provided from the outside.

More importantly though - Why do you want that information?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号