candland

@candland rss self
March 4th 2010

Resolve Lists and Arrays with Castle Windsor

I’ve worked with the Castle Project for a long time, primarily with Windsor. However, I often forget there are Array and List dependencies resolvers build-in, but they need to be wired up. This is mostly for my memory and hopefully it helps someone else.

This sub resolvers are in this namespace;

using Castle.MicroKernel.Resolvers.SpecializedResolvers;

Before registering components, add the sub resolvers;

container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));

container.Kernel.Resolver.AddSubResolver(new ListResolver(container.Kernel));

Use like this, where there are multiple IService implementations that are needed by the DependsOnArrayOrList class. 

public class DependsOnArrayOrList

{

    public DependsOnArrayOrList(IService[] services)

    {

    }

 

    public DependsOnArrayOrList(IList<IService> services)

    {

    }

}

 

public interface IService

{

}

Not sure why these sub resolvers are not setup by default, but regardless they’re easy to setup and come in handy.

Digg This

blog comments powered by Disqus