【发布时间】:2013-11-18 15:48:56
【问题描述】:
是否可以将企业库块的配置拆分为多个文件?
例如:我有三个程序集和一个托管项目。我想将 每个程序集 的 entlib v6 异常处理应用程序块 (EHAB) 配置存储在位于特定程序集的 单独配置文件 中。
托管项目引用了三个程序集:
组装_X
- ehabX.config
组装_Y
- ehabY.config
组装_Z
- ehabZ.config
托管项目
- 使用 ehabX.config
- 使用 ehabY.config
- 使用 ehabZ.config
我已经尝试了以下方法:
托管项目中的 App.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common" requirePermission="true" />
</configSections>
<enterpriseLibrary.ConfigurationSource>
<sources>
<add name="ehabX" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabX.config" />
<add name="ehabY" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabY.config" />
<add name="ehabZ" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabZ.config" />
</sources>
<redirectSections>
<add sourceName="ehabX" name="exceptionHandling" />
<add sourceName="ehabY" name="exceptionHandling" />
<add sourceName="ehabZ" name="exceptionHandling" />
</redirectSections>
</enterpriseLibrary.ConfigurationSource>
</configuration>
ehabX.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Swallow NotImplementedException">
<exceptionTypes>
<add type="System.NotImplementedException, mscorlib" postHandlingAction="None" name="NotImplementedException"/>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
ehabY.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Swallow ArgumentException">
<exceptionTypes>
<add type="System.ArgumentException, mscorlib" postHandlingAction="None" name="NotImplementedException"/>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
ehabZ.config 被省略。
将 EHAB 与策略“Swallow NotImplementedException”一起使用可以正常工作。但是,如果我尝试使用 ehabY.config 中定义的策略“Swallow ArgumentException”,我会收到以下错误消息:
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException:找不到名为“Swallow ArgumentException”的策略。异常处理中止。
有什么建议吗?
【问题讨论】:
-
所以您想将配置拆分为多个文件,但在运行时将它们全部合并回一个配置集?
-
是的图佐,这就是我想做的事
标签: c# configuration enterprise-library configuration-files