以编程方式配置EntLib CAB CacheManager

时间:2009-09-03 20:52:55

标签: configuration cab enterprise-library caching-application-block

目前我不得不在app.config中包含一大块XML来获取CAB CacheManager,我宁愿在我的代码中隐藏配置。

有没有办法以编程方式配置企业库缓存应用程序块的CacheManager?

1 个答案:

答案 0 :(得分:1)

为什么不在web.config中使用configSource属性将CAB配置转移到另一个配置文件?

例如:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         ....


</configSections>

 <cachingConfiguration configSource="Config\Caching.config" />

然后,在Config \ Caching.config中:

<?xml version="1.0" encoding="utf-8" ?>
<cachingConfiguration defaultCacheManager="DefaultCacheManager">
    <cacheManagers>
        <add name="DefaultCacheManager"
             expirationPollFrequencyInSeconds="60"
             maximumElementsInCacheBeforeScavenging="1000"
             numberToRemoveWhenScavenging="10"
             backingStoreName="Null Storage"
             type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

...

据我所知,您可以为web.config中的每个configSection使用单独的配置文件

相关问题