Castle Windsor - Null constructor argument
Asked Answered
D

3

6

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>`
Deutschland answered 11/12, 2008 at 18:26 Comment(0)
B
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.

Bokbokhara answered 31/1, 2009 at 22:15 Comment(0)
A
1

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?

Affair answered 11/12, 2008 at 18:31 Comment(0)
B
1

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.

Ballenger answered 11/12, 2008 at 18:32 Comment(1)
I think the reason is actually that constructor arguments are mandatory dependencies, so null makes no sense there.Jaala

© 2022 - 2024 — McMap. All rights reserved.