Enterprise Library: Configuration Application Block类设计分析篇
Enterprise Library: Configuration Application Block類設(shè)計(jì)分析篇<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
?
Written by: Rickie Lee (rickieleemail#yahoo.com)
My blog: www.cnblogs.com/rickie
Configuration Application Block允許應(yīng)用程序方便讀寫應(yīng)用程序配置信息。
下圖顯示了Configuration Application Block中類和對(duì)象之間的關(guān)系,該圖假定你使用Application Block內(nèi)置的XML文件Storage Provider和Transformer,XML文件Storage Provider存放配置數(shù)據(jù)到XML文件中(其他Providers使用其他Storage格式,如Windows注冊(cè)表)。XmlFileStorageProvider對(duì)象指向包含特定配置節(jié)配置信息的文件。ConfigurationBuilder對(duì)象指向包含特定配置節(jié)配置元數(shù)據(jù)的文件。一般情況下,包含配置元數(shù)據(jù)的文件為Windows應(yīng)用程序的App.Config或Web應(yīng)用程序的Web.Config文件。
Configuration Application Block隔離配置元數(shù)據(jù)和實(shí)際配置文件,Application Block將元數(shù)據(jù)放置在它自己的配置文件中,與實(shí)際的配置信息進(jìn)行隔離。配置設(shè)置被組合在一起,并作為一個(gè)配置節(jié)。應(yīng)用程序中每一個(gè)Enterprise Library的Application Block均使用它自己的配置節(jié),并有對(duì)應(yīng)的配置文件。Configuration Application Block通過使用配置元數(shù)據(jù)來訪問配置數(shù)據(jù)。
?
配置元數(shù)據(jù)包含有配置存儲(chǔ)位置、Transformer類型和Configuration Application Block用來讀寫配置數(shù)據(jù)的Storage Provider等等信息。配置元數(shù)據(jù)文件分成一些配置節(jié),每一節(jié)包含讀寫配置設(shè)置中特定組的必要信息。ConfigurationManager類提供了靜態(tài)方法在定義的存儲(chǔ)位置讀寫指定配置節(jié)的配置設(shè)置。首先,ConfigurationManager對(duì)象從應(yīng)用程序配置元數(shù)據(jù)文件讀取配置元數(shù)據(jù)信息,然后通過元數(shù)據(jù)信息讀寫配置節(jié)信息。
?
每一個(gè)配置節(jié)的設(shè)置都緩存在hashtable中。當(dāng)client端請(qǐng)求配置數(shù)據(jù)時(shí),ConfigurationBuilder將查詢緩存中的數(shù)據(jù)。如果在緩存中發(fā)現(xiàn)這些配置數(shù)據(jù),ConfigurationBuilder對(duì)象則不訪問存儲(chǔ)區(qū)的配置數(shù)據(jù)。如果Storage Provider檢測(cè)存儲(chǔ)區(qū)內(nèi)的數(shù)據(jù)發(fā)生變化,ConfigurationBuilder將清除緩存。ConfigurationManager對(duì)象允許應(yīng)用程序清除整個(gè)或特定配置節(jié)的緩存,如果緩存被清除后,隨后的請(qǐng)求將訪問存儲(chǔ)區(qū)中的配置數(shù)據(jù)。
?
IStorageProviderReader接口定義了用來從存儲(chǔ)位置讀取配置信息,IStorageProviderWriter接口實(shí)現(xiàn)了IStorageProviderReader接口,并且定義了用來寫配置信息的接口。Configuration Application Block中的XmlFileStorageProvider實(shí)現(xiàn)了上述接口,用來讀寫XML配置文件。
ITransformer接口用來在應(yīng)用程序與Storage Provider之間轉(zhuǎn)換配置設(shè)置對(duì)象,Configuration Application Block中的XmlSerializerTransformer類實(shí)現(xiàn)了該接口。XmlSerializerTransformer類轉(zhuǎn)換應(yīng)用程序中定義的對(duì)象和XmlNode對(duì)象。應(yīng)用程序不是必須要求配置Transformer,如果沒有Transformer,返回給應(yīng)用程序的配置設(shè)置對(duì)象與Storage Provider提供的對(duì)象類型一樣。
?
***
作者:Rickie Lee (rickieleemail#yahoo.com)
本文參考Enterprise Library, Configuration Application Block文檔。
?
References:
1. Enterprise Library, Configuration Application Block
2. Rickie, Microsoft patterns & practices Enterprise Library January 2005 [中文稿], http://www.cnblogs.com/rickie/archive/2005/01/30/99443.html
3. Rickie, Enterprise Library released! http://www.cnblogs.com/rickie/archive/2005/01/29/99106.html
?
轉(zhuǎn)載于:https://www.cnblogs.com/rickie/archive/2005/02/11/103772.html
總結(jié)
以上是生活随笔為你收集整理的Enterprise Library: Configuration Application Block类设计分析篇的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WEB页面多语言支持解决方案(转自CSD
- 下一篇: 经理人必看三部电影