Search code examples
c#asp.net-mvcninjectunity-containerenterprise-library

Has anybody used Ninject and the MS Enterprise Caching application block?


I am putting together a reporting service based on a very slow connection to a backing (dare I say legacy) data store. The only access I have to the data store is via a web services SDK written in java.

I have a MVC3 C# front end using Ninject for the DI. The list of pre-canned reports and the prompts for parameters are unlikely to change frequently. There are some prompts that I need better control over for both freshness and security (the user list).

I have done a proof of concept using the System.Web.Caching.Cache but it does not offer the control I need over the data in the cache. I would like to use the MS Enterprise Application Caching Block because it does offer the control. I do not want to add Unity to the application (period, 'nuff said).

Has anybody used Ninject to resolve the ICacheManager / CacheManager?


Solution

  • Seems I was making this way (way, way) more complicated then it needed to be.

    Instructions to implement the Application Block Caching without Unity and without Instrumentation.

    Add the following to your config file:

    <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching" requirePermission="true" />
    ...
    <cachingConfiguration defaultCacheManager="Default">
      <cacheManagers>
        <add name="Default" expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="10000" numberToRemoveWhenScavenging="100" backingStoreName="NullBackingStore" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching" />
      </cacheManagers>
      <backingStores>
        <add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching" name="NullBackingStore" />
      </backingStores>
    </cachingConfiguration>
    

    Where you need the cache declare:

    ICacheManager _cache = CacheFactory.GetCachemanager();
    

    You can then use the full width and depth of the caching block.