constructedValue element
The constructedValue element is used to construct a value in configuration file.
The constructedValue element can be used recursively in another constructedValue to specify the constructor parameter or injected property values.
Note
Refer to IoCConfiguration_constructedValue.xml for more examples on constructedValue element.
Below are some examples of using constructedValue element.
Example 1: Using constructedValue element to define a setting of type IoC.Configuration.Tests.ConstructedValue.Services.AppInfo
1<settings>
2 <object name="App1" typeRef="IAppInfo" value="1, App 1"/>
3
4 <!--AppInfo is declared in element typeDefinitions, and references a type
5 IoC.Configuration.Tests.ConstructedValue.Services.AppInfo. -->
6 <constructedValue name="App2" typeRef="AppInfo" >
7 <parameters>
8 <int32 name="Id" value="2"/>
9 </parameters>
10 <injectedProperties>
11 <string name="Description" value="App 2"/>
12 </injectedProperties>
13 </constructedValue>
14</settings>
Example 2: Using constructedValue element to define a service implementation
1<services>
2 <service typeRef="IAppInfo">
3 <valueImplementation scope="singleton">
4 <!--Demo of constructedValue to provide an implementation
5 for a service under valueImplementation element.-->
6 <constructedValue typeRef="AppInfo">
7 <parameters>
8 <int32 name="id" value="8"/>
9 </parameters>
10 <injectedProperties>
11 <string name="Description" value="App 8"/>
12 </injectedProperties>
13 </constructedValue>
14 </valueImplementation>
15 </service>
16</services>
Example 3: Using constructedValue element to specify a value returned in autoProperty element
1<autoGeneratedServices>
2 <autoService interface="IoC.Configuration.Tests.ConstructedValue.Services.IAppInfoFactory">
3 <autoProperty name="DefaultAppInfo" returnTypeRef="IAppInfo">
4 <constructedValue typeRef="AppInfo" >
5 <parameters>
6 <int32 name="id" value="11"/>
7 </parameters>
8 <injectedProperties>
9 <string name="Description" value="App 11"/>
10 </injectedProperties>
11 </constructedValue>
12 </autoProperty>
13 </autoService>
14</autoGeneratedServices>
Example 4: Using constructedValue element to specify a value returned in autoMethod element
1<autoGeneratedServices>
2 <autoService interface="IoC.Configuration.Tests.ConstructedValue.Services.IAppInfoFactory">
3 <autoMethod name="CreateAppInfo" returnTypeRef="IAppInfo">
4 <default>
5 <constructedValue typeRef="AppInfo" >
6 <parameters>
7 <int32 name="id" value="12"/>
8 </parameters>
9 <injectedProperties>
10 <string name="Description" value="App 12"/>
11 </injectedProperties>
12 </constructedValue>
13 </default>
14 </autoMethod>
15 </autoService>
16</autoGeneratedServices>
Example 5: Using constructedValue element as a parameter value in another constructedValue element
1<settings>
2 <constructedValue
3 name="DecoratedAppInfo"
4 type="IoC.Configuration.Tests.ConstructedValue.Services.AppInfoDecorator">
5 <parameters>
6 <constructedValue
7 name="appInfo"
8 type="IoC.Configuration.Tests.ConstructedValue.Services.AppInfoDecorator">
9 <parameters>
10 <constructedValue name="appInfo" typeRef="AppInfo">
11 <parameters>
12 <int32 name="id" value="25"/>
13 </parameters>
14 <injectedProperties>
15 <string name="Description" value="App 25"/>
16 </injectedProperties>
17 </constructedValue>
18 </parameters>
19 </constructedValue>
20 </parameters>
21 </constructedValue>
22</settings>