从各个位置加载自定义配置部分

时间:2014-02-13 20:00:56

标签: c# asp.net

目前我正面临着我正在开发的框架的问题。 我有一个处理数据缓存的自定义配置部分。

此配置存储在应用程序的web.config中,如下所示。

<configSections>
<section name="CachingProviders"
         type="Data.Caching.Providers.Configuration.CachingProviderConfigurationSection, Data.Caching" />
</configSections>

<!-- Start the DCF configuration here. -->
<CachingProviders>
<!-- Providers definition:
A provider is the object that make sure that the item can be stored in the cache or not.
-->
<Providers>
  <Provider Name="SlidingCachingProvider" Time="5" IsDefault="False"
            Type="Data.Caching.Providers.SlidingProvider, Data.Caching.Providers" />
  <Provider Name="AbsoluteCachingProvider" Time="5" IsDefault="False"
            Type="Data.Caching.Providers.AbsoluteProvider, Data.Caching.Providers" />
</Providers>
</CachingProviders>

现在,代码工作正常,我正在从web.config中读取配置

但现在我想知道是否有一种简单的方法来转换我的代码,以便配置可以在bin目录中的单独文件中完成,例如:data-caching.config

我知道有一个解决方案,在自定义配置部分中定义要加载的文件,但我想保持我的web.config尽可能干净,这意味着我不想添加单个内容可能的。

1 个答案:

答案 0 :(得分:0)

您可以将configSource属性添加到Providers节点:

<Providers configSource="providers.config"/>

请参阅herehere。这也适用于自定义部分。