Use Unity (ii): Configure unity, read configuration information and get objects

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.