List all types registered with a Castle Windsor co

2019-01-18 02:52发布

问题:

What's the easiest way of programatically listing registered types in Castle Windsor?

Thanks

回答1:

Use IKernel.GetAssignableHandlers(typeof(object)):

IWindsorContainer container = ...

foreach (var handler in container.Kernel.GetAssignableHandlers(typeof(object))) {
    Console.WriteLine("{0} {1}", 
       handler.ComponentModel.Service, 
       handler.ComponentModel.Implementation);
}