IoCConfiguration_classMember.xmlΒΆ

This configuration file can be downloaded downloaded from IoCConfiguration_classMember.xml.

  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
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<?xml version="1.0" encoding="utf-8"?>

<!--
   The XML configuration file is validated against schema file IoC.Configuration.Schema.7579ADB2-0FBD-4210-A8CA-EE4B4646DB3F.xsd,
   which can be found in folder IoC.Configuration.Content in output directory.
   The schema file can also be downloaded from
   http://oroptimizer.com/ioc.configuration/V2/IoC.Configuration.Schema.7579ADB2-0FBD-4210-A8CA-EE4B4646DB3F.xsd or in source code
   project in Github.com.

   To use Visual Studio code completion based on schema contents, right click Properties on this file in Visual Studio, and in Schemas
   field pick the schema IoC.Configuration.Schema.7579ADB2-0FBD-4210-A8CA-EE4B4646DB3F.xsd.

   Before running the tests make sure to execute IoC.Configuration\Tests\IoC.Configuration.Tests\PostBuildCommands.bat to copy the dlls into
   folders specified in this configuration file.
   Also, modify the batch file to copy the Autofac and Ninject assemblies from Nuget packages folder on machine, where the test is run.
-->

<iocConfiguration
     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
     xsi:noNamespaceSchemaLocation="http://oroptimizer.com/IoC.Configuration/V2/IoC.Configuration.Schema.7579ADB2-0FBD-4210-A8CA-EE4B4646DB3F.xsd">

    <!--The application should have write permissions to path specified in appDataDir.
      This is where dynamically generated DLLs are saved.-->
    <!--NOTE: path should be an absolute path, or should be converted to absolute path by some implementation of
     IoC.Configuration.AttributeValueTransformer.IAttributeValueTransformer. In this example the paths are converted by
     IoC.Configuration.Tests.FileFolderPathAttributeValueTransformer.-->
    <appDataDir
            path="TestFiles\AutogeneratedDlls\DynamicFiles_ClassMemberTests"/>

    <plugins
            pluginsDirPath="TestFiles\PluginDlls">

        <!--
            Plugin assemblies will be in a folder with similar name under pluginsDirPath folder.
            The plugin folders will be included in assembly resolution mechanism.
            -->

        <!--A folder K:\...\IoC.Configuration\Tests\IoC.Configuration.Tests\bin\TestFiles\PluginDlls\Plugin1 should exist.  -->
        <plugin name="Plugin1"/>
        <plugin name="Plugin2" enabled="true"/>
        <plugin name="Plugin3" enabled="false"/>
    </plugins>

    <additionalAssemblyProbingPaths>
        <probingPath
                path="TestFiles\ThirdPartyLibs"/>
        <probingPath
                path="TestFiles\ContainerImplementations\Autofac"/>
        <probingPath
                path="TestFiles\ContainerImplementations\Ninject"/>
        <probingPath
                path="TestFiles\DynamicallyLoadedDlls"/>
    </additionalAssemblyProbingPaths>

    <assemblies>
        <!--Assemblies should be in one of the following locations:
            1) Executable's folder
            2) In folder specified in additionalAssemblyProbingPaths element.
            3) In one of the plugin folders specified in plugins element (only for assemblies with plugin attribute) -->

        <!--
        Use "overrideDirectory" attribute, to make the assembly path explicit, rather then searching for
        an assembly in predefined folders, which also include probing paths specified in additionalAssemblyProbingPaths element.
        -->
        <assembly name="IoC.Configuration.Autofac" alias="autofac_ext"/>
        <assembly name="IoC.Configuration.Ninject" alias="ninject_ext"/>

        <assembly name="TestProjects.Modules" alias="modules"/>

        <assembly name="TestProjects.DynamicallyLoadedAssembly1"
                  alias="dynamic1"/>

        <assembly name="TestProjects.DynamicallyLoadedAssembly2"
                  alias="dynamic2"/>

        <assembly name="TestProjects.TestPluginAssembly1"
                  alias="pluginassm1" plugin="Plugin1"/>

        <assembly name="TestProjects.TestPluginAssembly2"
                  alias="pluginassm2" plugin="Plugin2"/>

        <assembly name="TestProjects.TestPluginAssembly3"
                  alias="pluginassm3" plugin="Plugin3"/>

        <assembly name="TestProjects.ModulesForPlugin1"
                  alias="modules_plugin1" plugin="Plugin1"/>

        <assembly name="TestProjects.SharedServices" alias="shared_services"/>

        <assembly name="IoC.Configuration.Tests" alias="tests"/>
    </assemblies>

    <typeDefinitions>
        <typeDefinition alias="ConstAndStaticAppIds"
                        type="IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds"/>
        <typeDefinition alias="IAppIds" type="IoC.Configuration.Tests.ClassMember.Services.IAppIds"/>
        <typeDefinition alias="AppTypes" type="IoC.Configuration.Tests.ClassMember.Services.AppTypes"/>
        <typeDefinition alias="AppInfo" type="IoC.Configuration.Tests.ClassMember.Services.AppInfo"/>
        <typeDefinition alias="StaticMethodsWithParameters"
                        type="IoC.Configuration.Tests.ClassMember.Services.StaticMethodsWithParameters"/>
    </typeDefinitions>

    <parameterSerializers>
        <serializers></serializers>
    </parameterSerializers>

    <!--The value of type attribute should be a type that implements
      IoC.Configuration.DiContainer.IDiManager-->
    <diManagers activeDiManagerName="Autofac">
        <diManager name="Ninject" type="IoC.Configuration.Ninject.NinjectDiManager"
                   assembly="ninject_ext">
            <!--
                  Use parameters element to specify constructor parameters,
                  if the type specified in 'type' attribute has non-default constructor.
                  -->
            <!--<parameters>
                  </parameters>-->
        </diManager>

        <diManager name="Autofac" type="IoC.Configuration.Autofac.AutofacDiManager"
                   assembly="autofac_ext">
        </diManager>
    </diManagers>

    <!--
      If settingsRequestor element is used, the type in type attribute should
      specify a type that implements IoC.Configuration.ISettingsRequestor.
      The implementation specifies a collection of required settings that should be present
      in settings element.
      Note, the type specified in type attribute is fully integrated into a dependency
      injection framework. In other words, constructor parameters will be injected using
      bindings specified in dependencyInjection element.
      -->

    <settings>

    </settings>

    <dependencyInjection>
        <modules>
            <!--<module type="IoC.Configuration.Tests.AutoService.AutoServiceTestsModule" />-->
            <module type="IoC.Configuration.Tests.ClassMember.Module1">
                <parameters>
                    <classMember name="param1" classRef="ConstAndStaticAppIds" memberName="DefaultAppId"/>
                    <classMember name="param2" classRef="StaticMethodsWithParameters" memberName="GetString">
                        <parameters>
                            <int32 name="intParam" value="5"/>
                            <string name="strParam" value="Value 1"/>
                        </parameters>
                    </classMember>
                </parameters>
            </module>
        </modules>
        <services>
            <service type="System.Int32">
                <valueImplementation scope="singleton">
                    <!--Example of classMember in valueImplementation. Since IAppIds.DefaultAppId is non-static,
                    IAppIds will be resolved from dependency injection container, and the value of property DefaultAppId of
                    resolved object will be bound to System.Int32
                    -->
                    <classMember classRef="IAppIds" memberName="DefaultAppId"/>

                </valueImplementation>
            </service>

            <!--<service type="System.String">
               <valueImplementation scope="singleton">
                  <object type="System.String" value="Test"/>
               </valueImplementation>
            </service>-->
            <service type="System.String">
                <valueImplementation scope="singleton">
                    <!--Example of classMember in valueImplementation. Since IAppIds.DefaultAppDescription is non-static,
                        IAppIds will be resolved from dependency injection container, and the value of property DefaultAppDescription of
                        resolved object will be bound to System.Int32
                    -->
                    <classMember classRef="IAppIds" memberName="DefaultAppDescription"/>
                   <!-- <object type="System.String" value="Test" />-->
                </valueImplementation>
            </service>


            <service type="IoC.Configuration.Tests.ClassMember.Services.IAppInfo">
                <!--The DI will try to construct IoC.Configuration.Tests.ClassMember.Services.AppInfo using the constructor
                with max number of parameters: AppInfo(int appId, string appDescription).
                Since we bound System.Int32, and System.String to IoC.Configuration.Tests.ClassMember.Services.IAppIds.DefaultAppId,
                and IoC.Configuration.Tests.ClassMember.Services.IAppIds.DefaultAppDescription, the values of injected
                appId and appDescription will be IoC.Configuration.Tests.ClassMember.Services.IAppIds.DefaultAppId and
                IoC.Configuration.Tests.ClassMember.Services.IAppIds.DefaultAppDescription.
                -->
                <implementation typeRef="AppInfo" scope="singleton">
                </implementation>
            </service>

            <service type="System.Collections.Generic.IReadOnlyList[System.Int32]">
                <valueImplementation scope="singleton">
                    <collection>
                        <!--Demo of classMember in collection element.-->
                        <classMember classRef="ConstAndStaticAppIds" memberName="AppId1"/>
                        <classMember classRef="IAppIds" memberName="DefaultAppId"/>
                    </collection>
                </valueImplementation>
            </service>

            <service type="IoC.Configuration.Tests.ClassMember.Services.IAppInfoFactory">
                <implementation type="IoC.Configuration.Tests.ClassMember.Services.AppInfoFactory" scope="singleton"/>
            </service>
        </services>

        <autoGeneratedServices>

            <!--The scope for autoService implementations is always singleton -->
            <autoService interfaceRef="IAppIds">
                <autoProperty name="DefaultAppId" returnType="System.Int32">
                    <!--Example of using classMember attribute in auto property.-->
                    <classMember class="System.Int32" memberName="MaxValue"/>
                </autoProperty>

                <autoProperty name="DefaultAppDescription" returnType="System.String">
                    <!--Example of using classMember attribute in auto property.-->
                    <classMember classRef="ConstAndStaticAppIds" memberName="DefaultAppDescription"/>
                </autoProperty>
            </autoService>

            <autoService interface="IoC.Configuration.Tests.ClassMember.Services.IAppInfos">
                <autoProperty name="AllAppInfos"
                              returnType="System.Collections.Generic.IReadOnlyList[IoC.Configuration.Tests.ClassMember.Services.IAppInfo]">
                    <collection>
                        <constructedValue typeRef="AppInfo">
                            <parameters>
                                <!--Property IoC.Configuration.Tests.ClassMember.Services.IAppIds.DefaultAppId is non-static, therefore
                                IoC.Configuration.Tests.ClassMember.Services.IAppIds will be resolved from dependency injection container,
                                and the value of property DefaultAppId in resolved object will be used as parameter value appId-->
                                <classMember name="appId" classRef="IAppIds" memberName="DefaultAppId"/>
                            </parameters>
                            <injectedProperties>
                                <!--Property IoC.Configuration.Tests.ClassMember.Services.IAppIds.DefaultAppId is non-static, therefore
                                IoC.Configuration.Tests.ClassMember.Services.IAppIds will be resolved from dependency injection container,
                                and the value of property DefaultAppId in resolved object will be used as parameter value appId-->
                                <classMember name="AppDescription" classRef="IAppIds"
                                             memberName="DefaultAppDescription"/>
                            </injectedProperties>
                        </constructedValue>

                        <!--
                        An example of calling a non static factory method to create an instance of IAppInfo.
                        Since method IoC.Configuration.Tests.ClassMember.Services.IAppInfoFactory.CreateAppInfo(appId, appDescription)
                        is non-static, an instance of IAppInfoFactory will be resolved using the DI container.
                        Also, since IAppInfoFactory is an interface, a binding for IAppInfoFactory should be configured in configuration
                        file or in some module.
                        -->
                        <classMember class="IoC.Configuration.Tests.ClassMember.Services.IAppInfoFactory"
                                     memberName="CreateAppInfo">
                            <parameters>
                                <int32 name="appId" value="1258"/>
                                <string name="appDescription" value="App info created with non-static method call."/>
                            </parameters>
                        </classMember>

                        <!--
                        An example of calling a static factory method to create an instance of IAppInfo.
                        -->
                        <classMember class="IoC.Configuration.Tests.ClassMember.Services.StaticAppInfoFactory"
                                     memberName="CreateAppInfo">
                            <parameters>
                                <int32 name="appId" value="1259"/>
                                <string name="appDescription" value="App info created with static method call."/>
                            </parameters>
                        </classMember>

                        <constructedValue typeRef="AppInfo">
                            <parameters>
                                <!--Method IoC.Configuration.Tests.ClassMember.Services.IAppIds.GetAppId() is non-static, therefore
                                IoC.Configuration.Tests.ClassMember.Services.IAppIds will be resolved from dependency injection container,
                                and the value returned by method IAppIds.GetAppId() will be used as parameter value appId-->
                                <classMember name="appId" classRef="IAppIds" memberName="GetAppId"/>
                            </parameters>
                        </constructedValue>

                        <constructedValue typeRef="AppInfo">
                            <parameters>
                                <!--Variable IoC.Configuration.Tests.ClassMember.Services.AppIdVars.NonStaticAppIdVar is non-static/non-constant, therefore
                                IoC.Configuration.Tests.ClassMember.Services.AppIdVars will be resolved from dependency injection container,
                                and the value variable NonStaticAppIdVarin resolved object will be used as parameter value appId
                                NOTE, no need to add a self bound service for IoC.Configuration.Tests.ClassMember.Services.AppIdVars, since
                                IoC.Configuration will generated one.
                                -->
                                <classMember name="appId" class="IoC.Configuration.Tests.ClassMember.Services.AppIdVars"
                                             memberName="NonStaticAppIdVar"/>
                            </parameters>
                        </constructedValue>

                        <constructedValue typeRef="AppInfo">
                            <parameters>
                                <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.AppId1 is a constant value.-->
                                <classMember name="appId" classRef="ConstAndStaticAppIds" memberName="AppId1"/>

                                <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.App1Description is a constant value.-->
                                <classMember name="appDescription" classRef="ConstAndStaticAppIds"
                                             memberName="App1Description"/>
                            </parameters>
                        </constructedValue>

                        <constructedValue typeRef="AppInfo">
                            <parameters>
                                <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.AppId2 is a static variable.-->
                                <classMember name="appId" classRef="ConstAndStaticAppIds" memberName="AppId2"/>

                                <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.App2Description is a static variable.-->
                                <classMember name="appDescription" classRef="ConstAndStaticAppIds"
                                             memberName="App2Description"/>
                            </parameters>
                        </constructedValue>

                        <constructedValue typeRef="AppInfo">
                            <parameters>
                                <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.AppId3 is a static property.-->
                                <classMember name="appId" classRef="ConstAndStaticAppIds" memberName="AppId3"/>

                                <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.GetApp3Description is a static function-->
                                <classMember name="appDescription" classRef="ConstAndStaticAppIds"
                                             memberName="GetApp3Description"/>
                            </parameters>
                        </constructedValue>

                        <constructedValue typeRef="AppInfo">
                            <parameters>
                                <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.GetAppId4() is a static method.-->
                                <classMember name="appId" classRef="ConstAndStaticAppIds" memberName="GetAppId4"/>

                                <string name="appDescription" value="App 4"/>
                            </parameters>
                        </constructedValue>

                        <constructedValue typeRef="AppInfo">
                            <parameters>
                                <!--IoC.Configuration.Tests.ClassMember.Services.AppTypes.App1 is an enum value.-->
                                <classMember name="appId" classRef="AppTypes" memberName="App1"/>
                            </parameters>
                        </constructedValue>
                    </collection>
                </autoProperty>
            </autoService>

            <autoService interface="IoC.Configuration.Tests.ClassMember.Services.IAppIdToPriority">
                <autoMethod name="GetPriority" returnType="System.Int32">
                    <methodSignature>
                        <int32 paramName="appId"/>
                    </methodSignature>

                    <!--Property IoC.Configuration.Tests.ClassMember.Services.IAppIds.DefaultAppId is non-static, therefore
                      IoC.Configuration.Tests.ClassMember.Services.IAppIds will be resolved from dependency injection container,
                      and the value of property DefaultAppId in resolved object will be used in if condition-->
                    <if parameter1="_classMember:IAppIds.DefaultAppId">
                        <int32 value="14"/>
                    </if>

                    <!--Method IoC.Configuration.Tests.ClassMember.Services.IAppIds.GetAppId() is non-static, therefore
                      IoC.Configuration.Tests.ClassMember.Services.IAppIds will be resolved from dependency injection container,
                      and the value returned by method IAppIds.GetAppId()  will be used in if condition-->
                    <if parameter1="_classMember:IAppIds.GetAppId">
                        <int32 value="25"/>
                    </if>

                    <!--Variable IoC.Configuration.Tests.ClassMember.Services.AppIdVars.NonStaticAppIdVar is non-static/non-constant, therefore
                       IoC.Configuration.Tests.ClassMember.Services.AppIdVars will be resolved from dependency injection container,
                       and the value variable NonStaticAppIdVarin resolved object will be used in if condition.
                       NOTE, no need to add a self bound service for IoC.Configuration.Tests.ClassMember.Services.AppIdVars, since
                       IoC.Configuration will generated one. -->
                    <if parameter1="_classMember:IoC.Configuration.Tests.ClassMember.Services.AppIdVars.NonStaticAppIdVar">
                        <int32 value="23"/>
                    </if>

                    <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.AppId1 is a constant value.-->
                    <if parameter1="_classMember:ConstAndStaticAppIds.AppId1">
                        <int32 value="4"/>
                    </if>

                    <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.AppId2 is a static variable.-->
                    <if parameter1="_classMember:ConstAndStaticAppIds.AppId2">
                        <int32 value="7"/>
                    </if>

                    <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.AppId3 is a static property.-->
                    <if parameter1="_classMember:ConstAndStaticAppIds.AppId3">
                        <int32 value="8"/>
                    </if>

                    <!--IoC.Configuration.Tests.ClassMember.Services.ConstAndStaticAppIds.GetAppId4() is a static method.-->
                    <if parameter1="_classMember:ConstAndStaticAppIds.GetAppId4">
                        <int32 value="5"/>
                    </if>

                    <default>
                        <int32 value="0"/>
                    </default>
                </autoMethod>

                <autoMethod name="GetPriority" returnType="System.Int32">
                    <methodSignature>
                        <object paramName="appType" type="IoC.Configuration.Tests.ClassMember.Services.AppTypes"/>
                    </methodSignature>
                    <!--Example of using _classMember in If statement to reference enum value.-->
                    <if parameter1="_classMember:IoC.Configuration.Tests.ClassMember.Services.AppTypes.App1">
                        <int32 value="8"/>
                    </if>

                    <!--Example of using _classMember in If statement to reference enum value.-->
                    <if parameter1="_classMember:IoC.Configuration.Tests.ClassMember.Services.AppTypes.App2">
                        <int32 value="9"/>
                    </if>
                    <default>
                        <int32 value="1"/>
                    </default>
                </autoMethod>
            </autoService>
        </autoGeneratedServices>
    </dependencyInjection>

    <startupActions>

    </startupActions>

    <pluginsSetup>
        <pluginSetup plugin="Plugin1">
            <!--The type in pluginImplementation should be non-abstract class
                      that implements IoC.Configuration.IPlugin and which has a public constructor-->
            <pluginImplementation type="TestPluginAssembly1.Implementations.Plugin1_Simple">
            </pluginImplementation>

            <settings>
                <int32 name="Int32Setting1" value="10"/>
                <string name="StringSetting1" value="Some text"/>
            </settings>

            <dependencyInjection>
                <modules>
                </modules>

                <services>
                </services>

                <autoGeneratedServices>
                </autoGeneratedServices>
            </dependencyInjection>
        </pluginSetup>

        <pluginSetup plugin="Plugin2">
            <pluginImplementation type="TestPluginAssembly2.Implementations.Plugin2" assembly="pluginassm2">
                <parameters>
                    <boolean name="param1" value="true"/>
                    <double name="param2" value="25.3"/>
                    <string name="param3" value="String value"/>
                </parameters>
            </pluginImplementation>
            <settings>
            </settings>
            <dependencyInjection>
                <modules>
                </modules>
                <services>
                </services>
                <autoGeneratedServices>
                </autoGeneratedServices>
            </dependencyInjection>
        </pluginSetup>

        <pluginSetup plugin="Plugin3">
            <pluginImplementation type="TestPluginAssembly3.Implementations.Plugin3" assembly="pluginassm3">

            </pluginImplementation>
            <settings>
            </settings>
            <dependencyInjection>
                <modules>
                </modules>
                <services>
                </services>
                <autoGeneratedServices>
                </autoGeneratedServices>
            </dependencyInjection>
        </pluginSetup>
    </pluginsSetup>
</iocConfiguration>