BETA1 Castle Windsor app.config for ICacheManager

Topics: Caching Application Block , Pre-release discussions
Feb 24, 2010 at 4:01 PM

I know this can be done but I don't know how. Our solution uses Castle Windsor for IoC, doing the configuration in the app.config. What would the configuration look like for the Caching Application Block? There are no examples available in the EntLib 5.0 BETA1 documentation (yet). The following is as far as I've got:

        <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=, Culture=neutral, PublicKeyToken=null" />
  <section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
    <cachingConfiguration defaultCacheManager="Cache Manager">
            <add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000"
                numberToRemoveWhenScavenging="10" backingStoreName="Null Storage"
                type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=, Culture=neutral, PublicKeyToken=null"
                name="Cache Manager" />
            <add encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=, Culture=neutral, PublicKeyToken=null"
                name="Null Storage" />
    service="Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, Microsoft.Practices.EnterpriseLibrary.Caching"
    type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching"/>        


Feb 25, 2010 at 7:03 AM
Edited Feb 25, 2010 at 7:58 AM

Haven't tried this either, but I don't think you should really register the entlib objects manually in the config, for e.g., in your case where you registered the ICacheManager, that would require you to register its dependencies, such as the Cache, BackgroundScheduller, etc.  From what I've read from the documentation, in order to use a different IoC container, I think you need to create an implementation of IContainerConfigurator.  I'll do some more digging and get back to you.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Feb 25, 2010 at 3:11 PM

A need to code up a container configurator would seem to break the ease with which we can declare our components and configure them. Hopefully it will be as simple as:

        service="Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, Microsoft.Practices.EnterpriseLibrary.Caching"
        type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching">

If not, why not? The team has said the blocks are usuable with IServiceLocator when other IoC frameworks are being used so I'm hoping they have example code somewhere.

I look forward to reading what you find out, Sarah.

Feb 27, 2010 at 4:21 AM

Entlib object creation is more complex than that, and always has been. The parameters in config end up translating not into a simple constructor call, but an entire graph of varying objects, with different values placed in different places. The point of the container configurator is that it's a single point that is delivered the configuration information in a pre-digested way so that you don't have to know the ins and outs of every little internal entlib type, you just use your existing entlib configuration and it just works.

The other thing is that there only needs to be one configurator written per container. We are hoping that, once EL5 gets out in the wild, that the communities around each container will write a configurator and make them available either on their site or on entlib contrib or somewhere else. You're on the bleeding edge right now, unfortunately, so those configurators don't exist yet (we have some proof of concepts we did internally, but cannot release them). The simplicity will come, and it'll be even easier, since you can use your same old Entlib config file, with the entlib config tool, and it'll all just work regardless of container.