settingValue element

The settingValue allows referencing a setting value in configuration file.

Note

For more details on settings see Settings.

Note

Refer to IoCConfiguration_settingValue_ReferencingInConfiguration.xml for more examples on settingValue element.

Example 1: Using settingValue element to provide a service implementation

1 <service type="System.Int32">
2    <valueImplementation scope="transient">
3      <!--Demo of using a setting value in valueImplementation.-->
4      <settingValue settingName="defaultInt"/>
5    </valueImplementation>
6 </service>

Example 2: Using settingValue element in collection element

 1 <service type="System.Collections.Generic.IReadOnlyList[System.Int32]">
 2    <valueImplementation scope="singleton">
 3        <collection>
 4            <!--Example of using setting value in collection element-->
 5            <settingValue settingName="defaultInt"/>
 6            <settingValue settingName="app1"/>
 7            <int32 value="78"/>
 8        </collection>
 9    </valueImplementation>
10 </service>

Example 3: Using settingValue element to specify constructor parameter and injected property values

 1<service type="IoC.Configuration.Tests.SettingValue.Services.IAppInfo" >
 2    <implementation type="IoC.Configuration.Tests.SettingValue.Services.AppInfo" scope="transient">
 3        <parameters>
 4            <!--Demo of using settingValue to inject value into an implementation constructor.-->
 5            <settingValue name="appId" settingName="defaultAppId"/>
 6        </parameters>
 7        <injectedProperties>
 8            <!--Demo of using settingValue to inject value into an implementation property.-->
 9            <settingValue name="AppDescription" settingName="defaultAppDescr"/>
10        </injectedProperties>
11    </implementation>
12</service>

Example 4: Referencing setting values in autoMethod and autoProperty elements

 1<autoGeneratedServices>
 2    <autoService interface="IoC.Configuration.Tests.SettingValue.Services.IAppIds">
 3        <autoMethod name="GetAppIds"
 4                    returnType="System.Collections.Generic.IReadOnlyList[System.Int32]">
 5            <methodSignature>
 6                <string paramName="platformType"/>
 7            </methodSignature>
 8
 9            <!--Demo of using the value of setting named "android" in if condition
10                in autoMethod-->
11            <if parameter1="_settings:android">
12                <collection>
13                    <!--Demo of setting value used as one of returned values in
14                    autoMethod if element.-->
15                    <settingValue settingName="defaultAppId"/>
16                    <settingValue settingName="app1"/>
17                    <int32 value="9"/>
18                </collection>
19            </if>
20
21            <default>
22              <collection>
23                <!--Demo of setting value used as one of returned values in
24                    autoMethod default element.-->
25                <settingValue settingName="defaultAppId"/>
26                <int32 value="8"/>
27              </collection>
28            </default>
29        </autoMethod>
30
31        <autoProperty name="MainAppId" returnType="System.Int32">
32            <!--Demo of setting value used as return value of autoProperty element.-->
33            <settingValue settingName="defaultAppId"/>
34        </autoProperty>
35    </autoService>
36</autoGeneratedServices>

Example 5: Referencing setting value in if element under autoMethod element

 1<autoService interface="IoC.Configuration.Tests.AutoService.Services.IActionValidatorFactory">
 2
 3    <autoMethod name="GetValidators"
 4                    returnType="System.Collections.Generic.IReadOnlyList[SharedServices.Interfaces.IActionValidator]"
 5                    reuseValue="true">
 6
 7        <methodSignature>
 8          <object paramName="actionType" typeRef="ActionTypes"/>
 9          <object paramName="projectGuid" type="System.Guid"/>
10        </methodSignature>
11
12        <!--Use _classMember: prefix in if elements to reference class member in if
13            condition in auto-implemented method.-->
14        <if parameter1="_classMember:ActionTypes.ViewFileContents" parameter2="_settings:Project1Guid">
15            <collection>
16                <injectedObject type="IoC.Configuration.Tests.AutoService.Services.ActionValidator1" />
17            </collection>
18        </if>
19
20        <default>
21            <collection>
22                <injectedObject type="SharedServices.Implementations.ActionValidator3" />
23                <injectedObject type="DynamicallyLoadedAssembly2.ActionValidator4"/>
24            </collection>
25        </default>
26    </autoMethod>
27<autoService>