Question

I am trying to initiate a class that is expecting a System.Type in it's CTOR.

Is there a way in spring.net config file to accomplish this, and preferable pass the type of a spring initialised object?

Thanks,

Lihnid

Was it helpful?

Solution

I think that this should do it:

<constructor-arg name="argumentname" expression="T(namespace.to.my.type, assemblyname)" />

OTHER TIPS

This also works:

<constructor-arg name="argumentname" value="MyNamespace.MyType, MyAssembly"/>

Use VS2010 Add-In for intellisense: http://www.springframework.net/vsaddin/

You can use an expression to inject a type:

<!-- use an expression to specify type -->
<constructor-arg type="System.Type, mscorlib" 
                 expression="T(MyNameSpace.MySecondClass)" />

To get the type of a spring-managed object, you can use the expression="@(object-id-here)" syntax to use a spring-managed object in your expression and simply call GetType() on it:

<!-- inject the type of MySecondObject, configured elsewhere -->
<constructor-arg type="System.Type, mscorlib" 
                 expression="@(MySecondObject).GetType()" />

Just in case if anyone is wondering how to do this with using the System.Type as the dictionary key.

<object id="myDictionary" type="System.Collections.Generic.Dictionary&lt;System.Type,string&gt;">
    <constructor-arg name="dictionary">
        <dictionary key-type="System.Type" value-type="string">
            <entry value="myStringValue">
                <key>
                    <expression value="T(namespace.to.MyClassType)"></expression>
                </key>
            </entry>
        </dictionary>
    </constructor-arg>
</object>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top