Question

When I try to pass two parameters that are of the same type like so:

public IPercentage CreatePercentage(int part, int total)
{
    return _container.Resolve<T>(new Arguments(part, total));
}

To a constructor like so:

public Percentage(int part, int total)
{
   // ...
}

Then I get a System.ArgumentException: An item with the same key has already been added.

How can I pass arguments of same type?

  • The key thing is I would like to avoid using literal string names of the parameters to identify which arguments goes where
  • And instead use the order of the arguments
  • and just the fact that it is the only constructor that fits, although I'm guessing the dictionary implementation of Windsor does not allow that.
Was it helpful?

Solution

It's absolutely doable, correct call according to documentation is:

_container.Resolve<IPercentage>(new Arguments(new { part, total }));

But the preferred way is to use the TypedFactoryFacility. You should never call container from your code except the entry point and/or composition root.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top