Castle Windsor: setting a parameter value to an empty string

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

I get this error when I try either nothing or one place (names changed):

Cannot resolve optional dependency for 'test.User' (MyNamespace.MyObject). UserName parameter of type System.String

+3
source share
3 answers

It turned out that it is much easier and probably more correct to add a constructor that does not accept the parameters (s) that you want to leave empty.

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

, ? .

+2

, , null - ? :

<component id="emptyString" type="System.String, mscorlib" />

and then use it in node parameters:

<parameters> <someStringParameter>${emptyString}</someStringParameter> </parameters>

But there seems to be a simpler way.

0
source

Source: https://habr.com/ru/post/1739344/


All Articles