Configuration 以编程方式配置EntLib CAB CacheManager

Configuration 以编程方式配置EntLib CAB CacheManager,configuration,cab,enterprise-library,caching-application-block,Configuration,Cab,Enterprise Library,Caching Application Block,目前,我必须在app.config中包含大量XML来启动CAB CacheManager,我宁愿将配置隐藏在代码中 是否有任何方法可以通过编程方式配置企业库缓存应用程序块的CacheManager?为什么不在web.config中使用configSource属性来移动到另一个配置文件CAB配置 例如: <?xml version="1.0"?> <configuration> <configSections> <section n

目前,我必须在app.config中包含大量XML来启动CAB CacheManager,我宁愿将配置隐藏在代码中


是否有任何方法可以通过编程方式配置企业库缓存应用程序块的CacheManager?

为什么不在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使用单独的配置文件


s、

为什么不在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使用单独的配置文件


s、

不显示如何以编程方式做事,而是回答我的基本需求,所以我接受:)不显示如何以编程方式做事,而是回答我的基本需求,所以我接受:)