String -> String type conversion

Jun 25, 2009 at 4:01 PM

 

Hi!
There is a following  configuration :
<type type="IDbStorage"
    mapTo="DbStorage">
    <lifetime type="singleton"/>
    <typeConfig>
        <constructor>
            <param name="connectionString"  parameterType="System.String">
                <value value="cacheDb"
                     type="System.String"
                     typeConverter="ConnectionStringTypeConverter"/>
            </param>
        </constructor>
    </typeConfig>
</type>

Value of the connectionString is the name of the connection string in app.config. I would like the DbStorage constructor to receive not the name of the connection string, but it's value taken from the app.config. 
Unfortunately, the specified converter is NOT called, hence the provided value is a string by itself. Is it possible to solve this somehow?

 

Jun 26, 2009 at 2:47 PM

There is another post regarding a similar issue with the same cause (http://unity.codeplex.com/Thread/View.aspx?ThreadId=55758). In a nutshell, if the value type is a string, Unity never attempts to call the TypeConverter you specified.

I also posted my solution creating a new configuration element allowing you to specify values indirectly by referencing an appSetting key. I have created similar code for connectionString's. I will let you do the exercise of implementing that -- it should be pretty easy starting from that posting.

 

Jun 26, 2009 at 4:01 PM

Thanks! I've also found this post and did that way :) It's very frustrating that Unity is very poorly documented. I thought of switching to it from Spring.NET, where I coould solve all of the issues easely. But now I don't even know what to do, hence basic configuration settings takes that long