0

当我尝试传递两个相同类型的参数时,如下所示:

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

对于这样的构造函数:

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

然后我得到一个System.ArgumentException: An item with the same key has been added。

如何传递相同类型的参数?

  • 关键是我想避免使用参数的文字字符串名称来识别哪些参数去哪里
  • 而是使用参数的顺序
  • 只是它是唯一适合的构造函数,尽管我猜温莎的字典实现不允许这样做。
4

1 回答 1

2

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.

于 2014-03-05T05:34:26.187 回答