Cache Application Block and Unity

Topics: Caching Application Block , Enterprise Library Core, General discussion
May 28, 2008 at 9:31 AM
Hi All

I am using the cache application block and want to use Unity to resolve the cache instance.

However, I found that it couldn't get the default instancde and I need to type full name to get the instance. Why?

Not work :-
  cacheObj = container.Resolve<CacheManager>();

Work :-
  cacheObj = container.Resolve<CacheManager>("Cache Manager");

Web.Config for the cache.

  <cachingConfiguration defaultCacheManager="Cache Manager">
    <cacheManagers>
      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000"
        numberToRemoveWhenScavenging="10" backingStoreName="Null Storage"
        type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Cache Manager" />
    </cacheManagers>
    <backingStores>
      <add encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Null Storage" />
    </backingStores>
  </cachingConfiguration>

May 28, 2008 at 3:15 PM
Hi,

Resolve ICacheManager instead. CacheManager is a concrete class. You can resolve it using its name because it is specified directly, but for defaults only the interface is configured in the container.

Fernando


hnchan wrote:
Hi All

I am using the cache application block and want to use Unity to resolve the cache instance.

However, I found that it couldn't get the default instancde and I need to type full name to get the instance. Why?

Not work :-
  cacheObj = container.Resolve<CacheManager>();

Work :-
  cacheObj = container.Resolve<CacheManager>("Cache Manager");

Web.Config for the cache.

  <cachingConfiguration defaultCacheManager="Cache Manager">
    <cacheManagers>
      <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000"
        numberToRemoveWhenScavenging="10" backingStoreName="Null Storage"
        type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Cache Manager" />
    </cacheManagers>
    <backingStores>
      <add encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Null Storage" />
    </backingStores>
  </cachingConfiguration>