views:

470

answers:

4

How can I pass a null constuctor argument using Castle Windsor? I thought the following would work

<parameters> <repository>null</repository> <message>null</message> </parameters>

+1  A: 

Wouldn't it better to simply have an additional public constructor that doesn't take these parameters, then you wouldn't need to register the parameters in the config?

Macka
+1  A: 

This was discussed a while back on the mail list, and at the time I looked into the code. Null values are deliberately filtered out (mainly because the complicate type resolution).

I couldn't find a simple way to make a special case to add them.

James Curran
I think the reason is actually that constructor arguments are mandatory dependencies, so null makes no sense there.
Mauricio Scheffer
A: 

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.

Krzysztof Koźmic
A: 

This is not an answer, but I'm not sure what's the best way to ask a question or make a comment otherwise. This behavior of getting rid of null values has broken half of my unit tests that were expecting ArgumentNullExceptions, etc. I don't want to just remove those unit tests, and I'm not going to alter the public API of my library now. How do I get Castle Windsor to cooperate and just pass along null values so my negative unit tests can pass?

Roly