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

Example 2: Using settingValue element in collection element

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

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

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

Example 4: Referencing setting values in autoMethod and autoProperty elements

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<autoGeneratedServices>
    <autoService interface="IoC.Configuration.Tests.SettingValue.Services.IAppIds">
        <autoMethod name="GetAppIds"
                    returnType="System.Collections.Generic.IReadOnlyList[System.Int32]">
            <methodSignature>
                <string paramName="platformType"/>
            </methodSignature>

            <!--Demo of using the value of setting named "android" in if condition
                in autoMethod-->
            <if parameter1="_settings:android">
                <collection>
                    <!--Demo of setting value used as one of returned values in
                    autoMethod if element.-->
                    <settingValue settingName="defaultAppId"/>
                    <settingValue settingName="app1"/>
                    <int32 value="9"/>
                </collection>
            </if>

            <default>
              <collection>
                <!--Demo of setting value used as one of returned values in
                    autoMethod default element.-->
                <settingValue settingName="defaultAppId"/>
                <int32 value="8"/>
              </collection>
            </default>
        </autoMethod>

        <autoProperty name="MainAppId" returnType="System.Int32">
            <!--Demo of setting value used as return value of autoProperty element.-->
            <settingValue settingName="defaultAppId"/>
        </autoProperty>
    </autoService>
</autoGeneratedServices>

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<autoService interface="IoC.Configuration.Tests.AutoService.Services.IActionValidatorFactory">

    <autoMethod name="GetValidators"
                    returnType="System.Collections.Generic.IReadOnlyList[SharedServices.Interfaces.IActionValidator]"
                    reuseValue="true">

        <methodSignature>
          <object paramName="actionType" typeRef="ActionTypes"/>
          <object paramName="projectGuid" type="System.Guid"/>
        </methodSignature>

        <!--Use _classMember: prefix in if elements to reference class member in if
            condition in auto-implemented method.-->
        <if parameter1="_classMember:ActionTypes.ViewFileContents" parameter2="_settings:Project1Guid">
            <collection>
                <injectedObject type="IoC.Configuration.Tests.AutoService.Services.ActionValidator1" />
            </collection>
        </if>

        <default>
            <collection>
                <injectedObject type="SharedServices.Implementations.ActionValidator3" />
                <injectedObject type="DynamicallyLoadedAssembly2.ActionValidator4"/>
            </collection>
        </default>
    </autoMethod>
<autoService>