Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Castle Windsor: How to programatically pass a list parameter to the container?

Is it possible to pass a list constructor parameter when resolving a type? I want to use a programmatic configuration if possible. I've been playing around with the Parameters method as shown below, but I've not yet stumbled upon the answer.

container.Register(
    Component
    .For<IDoSomething>()
    .ImplementedBy<DoSomething>()
    .Parameters(...)
);

The DoSomething class would look something like this

public class DoSomething : IDoSomething
{
    public DoSomething(List<string> listOfStrings) 
    {
        ...
    }
}
like image 364
Ben Shepheard Avatar asked Dec 15 '08 16:12

Ben Shepheard


1 Answers

Aha!

container.Register(
    Component
    .For<IDoSomething>()
    .ImplementedBy<DoSomething>()
    .Parameters(new { listOfStrings = someList })
);
like image 161
Ben Shepheard Avatar answered Oct 03 '22 17:10

Ben Shepheard