0

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"

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response, Wiktor. It appears if I want to keep using some form of XML to define the passed object, I need to write a converter that uses XmlSerializer. Then I would use something like this: <value value="&lt;MyProviderSettings&gt;....." Not particularly convenient but should work. Is there a better solution?
I am afraid there is no other solution or at least nothing else comes to my mind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.