1: <?xml version="1.0" encoding="utf-8" ?>
2: configuration>
3:
4: configSections>
5: <section name="unity"
6: type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
7: Microsoft.Practices.Unity.Configuration, Version=1.1.0.0,
8: Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
9: /configSections>
10:
11: unity>
12:
13: <typeAliases>
14:
15: <!-- Lifetime manager types -->
16: <typeAlias alias="singleton"
17: type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager,
18: Microsoft.Practices.Unity" />
19: <typeAlias alias="external"
20: type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager,
21: Microsoft.Practices.Unity" />
22:
23: <!-- User-defined type aliases -->
24: <typeAlias alias="IMyInterface"
25: type="MyApplication.MyTypes.MyInterface, MyApplication.MyTypes" />
26: <typeAlias alias="MyRealObject"
27: type="MyApplication.MyTypes.MyRealObject, MyApplication.MyTypes" />
28: <typeAlias alias="IMyService"
29: type="MyApplication.MyTypes.MyService, MyApplication.MyTypes" />
30: <typeAlias alias="MyDataService"
31: type="MyApplication.MyTypes.MyDataService, MyApplication.MyTypes" />
32: <typeAlias alias="MyCustomLifetime"
33: type="MyApplication.MyLifetimeManager, MyApplication.MyTypes" />
34:
35: </typeAliases>
36:
37: <containers>
38:
39: <container name="containerOne">
40:
41: <types>
42:
43: <!-- Type mapping with no lifetime – defaults to "transient" -->
44: <type type="Custom.MyBaseClass" mapTo="Custom.MyConcreteClass" />
45:
46: <!-- Type mapping using aliases defined above -->
47: <type type="IMyInterface" mapTo="MyRealObject" name="MyMapping" />
48:
49: <!-- Lifetime managers specified using the type aliases -->
50: <type type="Custom.MyBaseClass" mapTo="Custom.MyConcreteClass">
51: <lifetime type="singleton" />
52: </type>
53: <type type="IMyInterface" mapTo="MyRealObject" name="RealObject">
54: <lifetime type="external" />
55: </type>
56:
57: <!-- Lifetime manager specified using the full type name -->
58: <!-- Any initialization data specified for the lifetime manager -->
59: <!-- will be converted using the default type converter -->
60: <type type="Custom.MyBaseClass" mapTo="Custom.MyConcreteClass">
61: <lifetime value="sessionKey"
62: type="MyApplication.MyTypes.MyLifetimeManager,
63: MyApplication.MyTypes" />
64: </type>
65:
66: <!-- Lifetime manager initialization using a custom TypeConverter -->
67: <type type="IMyInterface" mapTo="MyRealObject" name="CustomSession">
68: <lifetime type="MyCustomLifetime" value="ReverseKey"
69: typeConverter="MyApplication.MyTypes.MyTypeConverter,
70: MyApplication.MyTypes" />
71: </type>
72:
73: <!-- Object with injection parameters defined in configuration -->
74: <!-- Type mapping using aliases defined above -->
75: <type type="IMyService" mapTo="MyDataService" name="DataService">
76: <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement,
77: Microsoft.Practices.Unity.Configuration">
78: <constructor>
79: <param name="connectionString" parameterType="string">
80: <value value="AdventureWorks"/>
81: </param>
82: <param name="logger" parameterType="ILogger">
83: <dependency />
84: </param>
85: </constructor>
86: <property name="Logger" propertyType="ILogger" />
87: <method name="Initialize">
88: <param name="connectionString" parameterType="string">
89: <value value="contoso"/>
90: </param>
91: <param name="dataService" parameterType="IMyService">
92: <dependency />
93: </param>
94: </method>
95: </typeConfig>
96: </type>
97:
98: </types>
99:
100: <instances>
101: <add name="MyInstance1" type="System.String" value="Some value" />
102: <add name="MyInstance2" type="System.DateTime" value="2008-02-05T17:50:00" />
103: </instances>
104:
105: <extensions>
106: <add type="MyApp.MyExtensions.SpecialOne" />
107: </extensions>
108:
109: <extensionConfig>
110: <add name="MyExtensionConfigHandler"
111: type="MyApp.MyExtensions.SpecialOne.ConfigHandler" />
112: </extensionConfig>
113:
114: </container>
115:
116: <!-- ... more containers here ... -->
117:
118: </containers>
119:
120: </unity>
121:
122: </configuration>