Question

I have a class MyProvider that accepts a settings object as the constructor parameter. Does anyone know if Unity supports passing complex objects as parameters via app.config configuration?

Here's what I've tried so far (didn't work)

<register type="IProvider" mapTo="MyProvider">
    <constructor>
        <param name="settings">
            <value>
         <MyProviderSettings>
             <UserId>YYYYYYYY</UserId>
             <Password>XXXXXX</Password>
             <OtherPropery>ZZZZZZZ</OtherPropery>
         </MyProviderSettings>
        </value>
        </param>

I get an error "Invalid element MyProviderSettings"

Was it helpful?

Solution

Acording to the docs, you define a custom type converter for this. The type converter will convert a string value for any value of any type.

<constructor>
<param name="param1">
    <value value="42" />
</param>
<param name="param2">
    <value value="aieou" typeConverter="VowelTypeConverter" />
</param>
</constructor>

http://msdn.microsoft.com/en-us/library/ff660914(v=pandp.20).aspx#config_value

http://msdn.microsoft.com/en-us/library/ayybcxe5.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top