<?
xml version="1.0" encoding="utf-8"
?>
<
configuration
>
<
configSections
>
<
section
name
="unity"
type
="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
Microsoft patterns & practices – Unity Application Block 1.2 – October 2008 27
Microsoft.Practices.Unity.Configuration, =1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
/>
</
configSections
>
<
unity
>
<
typeAliases
>
<!--
Lifetime manager types
-->
<
typeAlias
alias
="singleton"
type
="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity"
/>
<
typeAlias
alias
="perThread"
type
="Microsoft.Practices.Unity.PerThreadLifetimeManager, Microsoft.Practices.Unity"
/>
<
typeAlias
alias
="external"
type
="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager, Microsoft.Practices.Unity"
/>
<!--
User-defined type aliases
-->
<
typeAlias
alias
="IMyInterface"
type
="MyApplication.MyTypes.MyInterface, MyApplication.MyTypes"
/>
<
typeAlias
alias
="MyRealObject"
type
="MyApplication.MyTypes.MyRealObject, MyApplication.MyTypes"
/>
<
typeAlias
alias
="IMyService"
type
="MyApplication.MyTypes.MyService, MyApplication.MyTypes"
/>
<
typeAlias
alias
="MyDataService"
type
="MyApplication.MyTypes.MyDataService, MyApplication.MyTypes"
/>
<
typeAlias
alias
="MyCustomLifetime"
type
="MyApplication.MyLifetimeManager, MyApplication.MyTypes"
/>
</
typeAliases
>
<
containers
>
<
container
name
="containerOne"
>
<
types
>
<!--
Type mapping with no lifetime – defaults to "transient"
-->
<
type
type
="Custom.MyBaseClass"
mapTo
="Custom.MyConcreteClass"
/>
<!--
Type mapping using aliases defined above
-->
<
type
type
="IMyInterface"
mapTo
="MyRealObject"
name
="MyMapping"
/>
<!--
Lifetime managers specified using the type aliases
-->
<
type
type
="Custom.MyBaseClass"
mapTo
="Custom.MyConcreteClass"
>
<
lifetime
type
="singleton"
/>
</
type
>
28 Microsoft patterns & practices – Unity Application Block 1.2 – October 2008
<
type
type
="IMyInterface"
mapTo
="MyRealObject"
name
="RealObject"
>
<
lifetime
type
="perThread"
/>
</
type
>
<
type
type
="IMyInterface"
mapTo
="MyRealObject"
name
="RealObject"
>
<
lifetime
type
="external"
/>
</
type
>
<!--
Lifetime manager specified using the full type name
-->
<!--
Any initialization data specified for the lifetime manager
-->
<!--
will be converted using the default type converter
-->
<
type
type
="Custom.MyBaseClass"
mapTo
="Custom.MyConcreteClass"
>
<
lifetime
value
="sessionKey"
type
="MyApplication.MyTypes.MyLifetimeManager, MyApplication.MyTypes"
/>
</
type
>
<!--
Lifetime manager initialization using a custom TypeConverter
-->
<
type
type
="IMyInterface"
mapTo
="MyRealObject"
name
="CustomSession"
>
<
lifetime
type
="MyCustomLifetime"
value
="ReverseKey"
typeConverter
="MyApplication.MyTypes.MyTypeConverter, MyApplication.MyTypes"
/>
</
type
>
<!--
Object with injection parameters defined in configuration
-->
<!--
Type mapping using aliases defined above
-->
<
type
type
="IMyService"
mapTo
="MyDataService"
name
="DataService"
>
<
typeConfig
extensionType
="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration"
>
<
constructor
>
<
param
name
="connectionString"
parameterType
="string"
>
<
value
value
="AdventureWorks"
/>
</
param
>
<
param
name
="logger"
parameterType
="ILogger"
>
<
dependency
/>
</
param
>
</
constructor
>
<
property
name
="Logger"
propertyType
="ILogger"
/>
<
method
name
="Initialize"
>
<
param
name
="connectionString"
parameterType
="string"
>
<
value
value
="contoso"
/>
</
param
>
<
param
name
="dataService"
parameterType
="IMyService"
>
<
dependency
/>
</
param
>
</
method
>
</
typeConfig
>
</
type
>
Microsoft patterns & practices – Unity Application Block 1.2 – October 2008 29
</
types
>
<
instances
>
<
add
name
="MyInstance1"
type
="System.String"
value
="Some value"
/>
<
add
name
="MyInstance2"
type
="System.DateTime"
value
="2008-02-05T17:50:00"
/>
</
instances
>
<
extensions
>
<
add
type
="MyApp.MyExtensions.SpecialOne"
/>
</
extensions
>
<
extensionConfig
>
<
add
name
="MyExtensionConfigHandler"
type
="MyApp.MyExtensions.SpecialOne.ConfigHandler"
/>
</
extensionConfig
>
</
container
>
<!--
... more containers here ...
-->
</
containers
>
</
unity
>
</
configuration
>