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<service type="System.Int32">
2    <valueImplementation scope="singleton">
3      <settingValue settingName="defaultAppId"/>
4    </valueImplementation>
5</service>

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

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

Example 3: Using valueImplementation to bind service to class member

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

Example 4: Using valueImplementation to bind service to collection

 1<service
 2    type="System.Collections.Generic.IReadOnlyList[IoC.Configuration.Tests.ValueImplementation.Services.IAppInfo]">
 3
 4    <valueImplementation scope="singleton" >
 5        <collection>
 6            <constructedValue typeRef="AppInfo">
 7              <parameters>
 8                <int32 name="paramId" value="1"/>
 9              </parameters>
10            </constructedValue>
11
12            <constructedValue typeRef="AppInfo">
13              <parameters>
14                <int32 name="paramId" value="2"/>
15              </parameters>
16            </constructedValue>
17        </collection>
18    </valueImplementation>
19</service>