Jelle Druyts .NET Consultant
Just another ignorant weirdo from Antwerp, Belgium trying to make sense out of it all
I've been using Enterprise Library 2.0 quite a lot lately, and although the configuration part is truly excellent and easy to use, sometimes you just want to use some block without going through configuration. In my case, I wanted to use a cache somewhere in a piece of framework code without requiring users of that code to add anything "magic" to their application configuration to make it work. So with a little help of Brian Button, I cooked up the following code to create a standard CacheManager with an in-memory backing store:
CacheManager
DictionaryConfigurationSource internalConfigurationSource = new DictionaryConfigurationSource(); CacheManagerSettings settings = new CacheManagerSettings(); internalConfigurationSource.Add(CacheManagerSettings.SectionName, settings); CacheStorageData storageConfig = new CacheStorageData("Null Storage", typeof(NullBackingStore)); settings.BackingStores.Add(storageConfig); CacheManagerData cacheManagerConfig = new CacheManagerData("CustomCache", 60, 1000, 10, storageConfig.Name); settings.CacheManagers.Add(cacheManagerConfig); settings.DefaultCacheManager = cacheManagerConfig.Name; CacheManagerFactory cacheFactory = new CacheManagerFactory(internalConfigurationSource); CacheManager customCache = cacheFactory.CreateDefault();
So this piece of code in fact creates the configuration objects directly and passes them on to the CacheManagerFactory to use so it doesn't go about reading any configuration files. Pretty simple once you get the hang of it, and pretty powerful for the cases you want to use Enterprise Library "behind the scenes".
CacheManagerFactory
Check out Brian's blog for an example on Exception Handling without using an external configuration file. By the way: thanks for all your work on EntLib and all the best in your career move, Brian!