/// <summary> /// Construct the ICacheProvider implementation using the configuration provided, the /// logging implementation provided, and the cache adapter resolver provided. If /// any of these items are passed as null, the existing values/settings are used. If there /// are no existing settings, then the default implementation is used. /// </summary> /// <param name="config">Configuration to use when creating the cache engine. if NULL /// is passed in, then the configuration is created based on values in the configuration file.</param> /// <param name="logger">The logging implementation to use. If NULL is provided, then the /// generic logging implementation is used.</param> /// <param name="resolver">The CacheAdapter resolver to use. If NULL is provided, the /// default resolver is used. You would typically provided your own resolver if you /// wanted to use different dependency resolution engines such as Ninject or Autofac which /// provide much richer lifetime support.</param> /// <returns></returns> public static ICacheProvider ResolveCacheFromConfig(CacheConfig config, ILogging logger = null, ICacheAdapterResolver resolver = null) { _config = config; _logger = logger; _resolver = resolver; EnsureObjectPropertiesAreValidObjects(); return(_resolver.ResolveCacheFromConfig(_config)); }
private static void EnsureObjectPropertiesAreValidObjects() { if (_config == null) { _config = new CacheConfig(); } if (_logger == null) { _logger = new Logger(_config); } if (_resolver == null) { _resolver = new CacheAdapterResolver(_logger); } }
/// <summary> /// Initialise the container with core dependencies. The cache/cache provider should be set to be /// singletons if adapting to use with a Dependency Injection mechanism /// </summary> /// <remarks>Note: In a .Net 4 web app, this method could be invoked using the new PreApplicationStartMethod attribute /// as in: <code>[assembly: PreApplicationStartMethod(typeof(MyStaticClass), "PreStartInitialise")]</code> /// Also note this section should be replaced with the DependencyInjection container of choice. This /// code simply acts as a cheap and simple utility mechanism for this without requiring a dependency on a /// container that you dont like/use. You can opt to replace the ICacheAdapterResolver with /// your resolver of choice as well to utilise your own dependency resolution mechanism. /// </remarks> public static void PreStartInitialise(ILogging logger = null, CacheConfig config = null, ICacheAdapterResolver resolver = null) { if (!_isInitialised) { lock (_lockRef) { if (!_isInitialised) { try { _cacheProvider = CacheBinder.ResolveCacheFromConfig(config, logger, resolver); CacheBinder.Logger.WriteInfoMessage(string.Format("Initialised cache of type: {0}", CacheBinder.Configuration.CacheToUse)); _cache = _cacheProvider.InnerCache; _isInitialised = true; } catch (Exception ex) { var outerEx = new ApplicationException(string.Format("Problem initialising cache of type: {0}", CacheBinder.Configuration.CacheToUse), ex); CacheBinder.Logger.WriteException(outerEx); throw outerEx; } } } } }
public static void SetDependencies(ILogging logger = null, CacheConfig config = null, ICacheAdapterResolver resolver = null) { _isInitialised = false; PreStartInitialise(logger, config, resolver); }
public static void SetResolver(ICacheAdapterResolver resolver) { _isInitialised = false; PreStartInitialise(null, null, resolver); }