Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Castle Windsor: Setting a parameter value to an empty string

How can I allow one of my string parameters to be an empty string?

I get this error when I try either nothing or a single space (names changed):

Could not resolve non-optional dependency for 'test.User' (MyNamespace.MyObject). Parameter 'userName' type 'System.String'

like image 884
Austin Salonen Avatar asked Dec 22 '22 04:12

Austin Salonen


2 Answers

Turns out it's much easier, and likely more correct, to add a constructor that doesn't take the parameter(s) you want to leave blank.

like image 172
2 revs Avatar answered Dec 24 '22 16:12

2 revs


container.Register(
   Component.For<Foo>()
      .DependsOn(new
      {
         someString = string.Empty
      }));

but first of all, why do you want to set that dependency to empty string? It does feel like hacking to me.

like image 43
Krzysztof Kozmic Avatar answered Dec 24 '22 18:12

Krzysztof Kozmic