Enumerating Registered Components in Windsor

Today I had occasion to want to know what’s in my IoC container (mine being Castle Windsor).

I poked and prodded to no avail, and finally ended up asking the Castle Project Users Google Group. The illustrious Hammet replied pointing me in the right direction, and this is what I ended up with:

public void LogComponentsInContainer(IWindsorContainer container)
{
    INamingSubSystem naming = container.Kernel.GetSubSystem(SubSystemConstants.NamingKey) as INamingSubSystem;
    foreach (var handler in naming.GetHandlers())
    {
        Log.Debug("Registered on IoC: {0}, {1}, {2}",
            handler.ComponentModel.Name,
            handler.Service.FullName,
            handler.ComponentModel.Implementation.FullName);
    }
}

It’s kinda icky, but it got ‘r did. I just wanted to log the registered components on startup so I could debug a silly Binsor issue.

This entry was posted in Development and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>