Unity Configuration - Method Element

May 26, 2009 at 1:43 PM

Is there a way to use the return value from a method call within Unity's Configuration?

May 27, 2009 at 4:08 AM

I'm not sure what you mean. Use a return value how? And where? In the config file? In an API call? Could you give a more detailed explanation of what you'd like to do?

Thanks,

-Chris

May 27, 2009 at 1:32 PM
Edited May 27, 2009 at 3:02 PM
Hi Chris,
Thanks for getting back to on this issue. I would like to use the return value from a method call in the configuration file. I understand that we can call / invoke a method using the "method element" and specify input parameters to the the method. What I would like to to do is to use the return value from such a method call.
If you look at the example below, I am to call a method however if this method returns a value I would like to use it. Specifically I have a Factory class which has Create method that returns an object instance, I would like to use that return value and register it in the container

<type type="SomeObject" mapTo="Samples.SomeObject, Samples" name="SomeObject">
<lifetime type="singleton" />
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement,
Microsoft.Practices.Unity.Configuration">
<method name="Initialize">
<param name="types"
parameterType="System.String[]">
<array>
<value value="StartupPath"/>
<value value="TempFolder"/>
</array>
</param>
</method>
</typeConfig>
</type>
<instances>
<add name="MyObject" type="Samples.SomeObject, Samples" value="[The return value]" />
</instances>

Thanks,
Venkatesh


From: ctavares [mailto:notifications@codeplex.com]
Sent: Wednesday, May 27, 2009 12:08 AM
To: Madhireddy, Venkatesh
Subject: Re: Unity Configuration - Method Element [unity:57478]

From: ctavares

I'm not sure what you mean. Use a return value how? And where? In the config file? In an API call? Could you give a more detailed explanation of what you'd like to do?

Thanks,

-Chris