Search code examples
c#.netcastle-windsorioc-containercastle

Passing parameters to UsingFactoryMethod in Castle Windsor


How do I pass dynamic parameters to a UsingFactoryMethod registration?

For example, I want to write something like:

container.Register(
   Component.For<IFoo>()
        .UsingFactoryMethod(return DoSomethingAndReturnInstance(paremeter)));

I need the parameters to be sent at runtime, like this:

container.Resolve<IFoo>(new { parameter = value });

How can it be done?


Solution

  • CreationContext.AdditionalParameters has the values you pass to Resolve