在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)示例代码下载

一般情况下,包含配置元数据的文件为Windows应用程序的App.Config或Web应用程序的Web.Config文件.这里介绍如何使用外部的置元数据的文件.

通常的方法
首先下面的一段代码是通常的做法,在App.config中写入配置信息,程序中用到了两个Block: Data Access Application Block和Exception Application Block.
AppService.vb

End Class

App.config

在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)<?xml version="1.0" encoding="utf-8"?>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
<configuration>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<exceptionHandling>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<exceptionPolicies>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      
<add name="rippleyong's Policy">
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)        
<exceptionTypes>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)          
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            postHandlingAction
="NotifyRethrow" name="Exception">
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            
<exceptionHandlers>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)              
<add exceptionMessage="Replace ExceptionMessage,Haha !!!" replaceExceptionType="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)                type
="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)                name
="Replace Handler" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            
</exceptionHandlers>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)          
</add>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)        
</exceptionTypes>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      
</add>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
</exceptionPolicies>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</exceptionHandling>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<connectionStrings>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<add name="rippleyong's ConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|ripple.mdf;User Instance=true;"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      providerName
="System.Data.SqlClient" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</connectionStrings>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
</configuration>

 
调用外部的配置元数据文件(结合程序配置文件)
如何使用外部的扩展配置元数据文件呢,这里需要通过配置工具(Enterprise Library Configuration)添加一个Configuration Sources 节点在App.config(web.config)中.添加一个选择File Configuration Source,在File中选择外部的配置元数据文件(在这里是ExternalApp.config)
Configuration Source结构图
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)

Enterprise Library Configuration
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)

App.config 

在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)<?xml version="1.0" encoding="utf-8"?>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
<configuration>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<sources>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      
<add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)        filePath
="C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\EnterpriseLibraryTest\EnterpriseLibraryTest\ExternalConfiguration\ExternalApp.config" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)     
<add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
</sources>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</enterpriseLibrary.ConfigurationSource>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
</configuration>

 ExternalApp.config

在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)<configuration>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<exceptionHandling>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<exceptionPolicies>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      
<add name="rippleyong's Policy">
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)        
<exceptionTypes>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)          
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            postHandlingAction
="NotifyRethrow" name="Exception">
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            
<exceptionHandlers>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)              
<add exceptionMessage="Rplace ExceptionMessage HaHa." replaceExceptionType="System.ApplicationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)                type
="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)                name
="Replace Handler" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            
</exceptionHandlers>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)          
</add>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)        
</exceptionTypes>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      
</add>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
</exceptionPolicies>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</exceptionHandling>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<connectionStrings>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<add name="rippleyong's connetionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|ripple.mdf;User Instance=true;"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)     providerName
="System.Data.SqlClient" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</connectionStrings>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
</configuration>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)

 

使用单独的ConfigurationSources
从上面的例子中我们可以看到,还是不是完全独立的,因为你必须在App.Config(Web.Config)中告诉Enterprise Library外部配置元数据文件的位置.
下面的代码演示了直接在程序中找到外部配置元数据文件.

data-filesource.config

在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)<?xml version="1.0" encoding="utf-8"?>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
<configuration>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<connectionStrings>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<add name="rippleyng's Connection" connectionString="Database=ripple;Server=(local)\SQLEXPRESS;Integrated Security=SSPI;"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      providerName
="System.Data.SqlClient" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</connectionStrings>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
</configuration>

exception-filesource.config

在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)<?xml version="1.0" encoding="utf-8"?>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
<configuration>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</configSections>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
<exceptionHandling>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
<exceptionPolicies>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      
<add name="rippleyong's Policy">
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)        
<exceptionTypes>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)          
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            postHandlingAction
="ThrowNewException" name="Exception">
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            
<exceptionHandlers>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)              
<add exceptionMessage="Rplace ExceptionMessage HaHa." replaceExceptionType="System.ApplicationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)                type
="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)                name
="Replace Handler" />
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)            
</exceptionHandlers>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)          
</add>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)        
</exceptionTypes>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)      
</add>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)    
</exceptionPolicies>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)  
</exceptionHandling>
在Enterprise Library for .NET Framework 2.0中使用外部的配置元数据的文件(my.config)
</configuration>

相关文章:

  • 2022-03-02
  • 2022-01-24
  • 2021-05-19
  • 2021-11-21
  • 2021-07-29
  • 2022-01-23
  • 2022-02-27
  • 2021-11-19
猜你喜欢
  • 2021-08-21
  • 2022-02-27
  • 2021-10-28
  • 2021-12-27
  • 2022-02-12
相关资源
相似解决方案