Inject property to constructor

Jun 4, 2008 at 6:21 AM
Hi,

Is it possible to inject property value of an object (singleton) into a constructor of another object (transient).
Eg:
1. Resolve SINGLETON (It has property PROP of type IPROPERTY).
2. Resolve TRANSIENT (constructor accepts IPROPERTY).

So when constructing 2 (TRANSIENT object) I want to pass SINGLETON.PROPERTY to its constructor.
How can it be done?

I assume the config should look like this:

<unity>
<typeAliases>
    <typeAlias alias="ISINGLETON" type="Project.ISINGLETON, Project"/>
    <typeAlias alias="IPROPERTY" type="
Project.IPROPERTY, Project"/>
    <typeAlias alias="ITRANSIENT" type="
Project.ITRANSIENT, Project"/>
</typeAliases>
<containers>
    <container>
        <types>
            <type type="
ISINGLETON" mapTo="Project.TheSingletonImplementation, Project">
                <lifetime type="singleton" />
            </type>          
            <type type="ITRANSIENT" mapTo="Project.MyTransientImplementation, Project">
                <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
                    <constructor>
                        <param name="property" parameterType="IPROPERTY">
                            <value value="How to assign a value from ISINGLETON instance's property PROPERTY?"/>
                        </param>
                    </constructor>
                </typeConfig>
            </type>
        </types>
    </container>
</containers>
</unity>


Thanks.