As with other application blocks of the Enterprise Library, Unity behavior can be specified by configuration.
The Unity Application Block can read configuration information from an XML configuration file. A configuration file can be a web.config of a app.config or asp.net application of a Windows Forms application. Of course, you can also load configuration information from any other XML-formatted file or from another data source.
In this article, we will work with you to learn about the format of the Unity configuration file, read the configuration, and get the example to illustrate the instance.
1. The Unity configuration file format
The Unity configuration file looks like this:
<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<configSections>
<section name= "Unity" type= "Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration "/>
</configSections>
<unity>
<containers >
<container name= "Containerone" >
<types>
<type type= "System.data.idbconnection,system.data"
mapto= "Doriandeng.unityconfigurationexe.mydefaultconnection,doriandeng.unityconfigurationexe"/>
<type name= "Basemap" type= "System.data.common.dbconnection,system.data"
Mapto= "Doriandeng.unityconfigurationexe.mydbconnection,doriandeng.unityconfigurationexe" lifetime= "Transient" >
<type name= "Interfacesingleton" type= "System.data.idbconnection,system.data"
Mapto= "Doriandeng.unityconfigurationexe.mydbconnection,doriandeng.unityconfigurationexe" lifetime= "Singleton" >
</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>
</container>
</containers>
</unity>
</configuration>