Element valueImplementation

Element valueImplementation can be used under element iocConfiguration/dependencyInjection/services/service (or iocConfiguration/pluginsSetup/pluginSetup/dependencyInjection/services/service for plugin section), to bind the service to a value specified using a value initialization element (e.g., such elements as int32, int64 collection, settingValue, classMember, object, constructedValue).

Note

Refer to Value Initialization Elements for details on value initialization elements.

Note

Refer to IoCConfiguration_valueImplementation.xml for more examples on valueImplementation element.

Example 1: Using valueImplementation to bind System.Int32 to a setting value

1
2
3
4
5
<service type="System.Int32">
    <valueImplementation scope="singleton">
      <settingValue settingName="defaultAppId"/>
    </valueImplementation>
</service>

Example 2: Using valueImplementation to bind System.Double to 3.5

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<service type="System.Double">
    <valueImplementation scope="singleton">
        <!--
            The out of the box serializer for System.Double is
            OROptimizer.Serializer.TypeBasedSimpleSerializerDouble
            which is available in Nuget package OROptimizer.Shared.
        -->
        <object type="System.Double" value="3.5"/>
    </valueImplementation>
</service>

Example 3: Using valueImplementation to bind service to class member

1
2
3
4
5
6
7
<service type="SharedServices.Interfaces.IDbConnection">
    <valueImplementation scope="transient">
        <classMember
            class="IoC.Configuration.Tests.ValueImplementation.Services.IDbConnectionProvider"
            memberName="GetDbConnection"/>
    </valueImplementation>
</service>

Example 4: Using valueImplementation to bind service to collection

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<service
    type="System.Collections.Generic.IReadOnlyList[IoC.Configuration.Tests.ValueImplementation.Services.IAppInfo]">

    <valueImplementation scope="singleton" >
        <collection>
            <constructedValue typeRef="AppInfo">
              <parameters>
                <int32 name="paramId" value="1"/>
              </parameters>
            </constructedValue>

            <constructedValue typeRef="AppInfo">
              <parameters>
                <int32 name="paramId" value="2"/>
              </parameters>
            </constructedValue>
        </collection>
    </valueImplementation>
</service>