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

1

6

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) 
    {
        ...
    }
}
Accomplice answered 15/12, 2008 at 16:12 Comment(0)
A
6

Aha!

container.Register(
    Component
    .For<IDoSomething>()
    .ImplementedBy<DoSomething>()
    .Parameters(new { listOfStrings = someList })
);
Accomplice answered 15/12, 2008 at 16:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.