Windsor Inspector

 Windsor  Comments Off
Feb 082012
 

Here is a useful utility class for inspecting the contents of the Windsor container:

public class WindsorContainerInspector
{
    private readonly IWindsorContainer _container;
    public WindsorContainerInspector(IWindsorContainer container)
    {
        _container = container;
    }
 
    public IList> ListDependencies()
    {
        var dependencies = new List>();
 
        foreach (var node in _container.Kernel.GraphNodes)
        {
            ComponentModel dependingNode = (ComponentModel) node;
 
            foreach (GraphNode depender in node.Dependents)
            {
                var dependerNode = (ComponentModel)depender;
 
                dependencies.Add(new KeyValuePair(
                        dependingNode, 
                        dependerNode));
            }
        }
 
        return dependencies;
    } 
}
 Posted by at 3:50 pm