6

如何使用 Castle Windsor 传递空构造函数参数?我认为以下会起作用

<parameters>
  <repository>null</repository>
  <message>null</message>
</parameters>`
4

3 回答 3

5

If you want them to be null, it means that they are non-essential dependencies. By having them as ctor arguments you suggest otherwise. You should redesign your class to have another constructor that takes only essential dependencies, if you wish that they not change throughout the lifetime of an object (be readonly), or expose them as properties.

With Windsor you can't make it to pass nulls, for reasons mentioned in the other answer.

于 2009-01-31T22:15:01.323 回答
1

简单地拥有一个不接受这些参数的额外公共构造函数不是更好,那么您就不需要在配置中注册参数了吗?

于 2008-12-11T18:31:44.297 回答
1

这在邮件列表上讨论过一段时间,当时我查看了代码。空值被故意过滤掉(主要是因为复杂的类型解析)。

我找不到一种简单的方法来制作特殊情况来添加它们。

于 2008-12-11T18:32:11.563 回答