public static FactoryBuilder RegisterConsolidationCache(this IUnityContainer container, bool autoRegister, string defaultCode = null) { return(container.RegisterCustomFactory(autoRegister, (context, customer) => { var currentCode = defaultCode ?? customer.CustomerCode; var logger = container.Resolve <ILogger>(); var cacheProvider = new VersionedCacheProviderBase(logger); var invalidator = new DpcContentInvalidator(cacheProvider, logger); var connectionProvider = new ExplicitConnectionProvider(customer); var tracker = new StructureCacheTracker(customer.ConnectionString, customer.DatabaseType); var watcher = new CustomerCoreCacheItemWatcher(InvalidationMode.All, TimeSpan.FromSeconds(15), invalidator, connectionProvider, logger, databaseType: customer.DatabaseType); context.Register <ICacheProvider>(currentCode, cacheProvider); context.Register(currentCode, cacheProvider); context.Register <IContentInvalidator>(currentCode, invalidator); context.Register <ICacheItemWatcher>(currentCode, watcher); watcher.AttachTracker(tracker); watcher.Start(); }) .For <ICacheProvider>(defaultCode) .For <VersionedCacheProviderBase>(defaultCode) .For <IContentInvalidator>(defaultCode) .For <ICacheItemWatcher>(defaultCode)); }
public CustomerCodeInstance(IConnectionProvider connectionProvider, ILogger logger) { CacheProvider = new VersionedCacheProviderBase(logger); Invalidator = new DpcContentInvalidator(CacheProvider, logger); var customer = connectionProvider.GetCustomer(); if (customer != null) { Watcher = new CustomerCoreCacheItemWatcher(InvalidationMode.All, TimeSpan.FromSeconds(15), Invalidator, connectionProvider, logger, databaseType: customer.DatabaseType); Tracker = new StructureCacheTracker(customer.ConnectionString, customer.DatabaseType); Watcher.AttachTracker(Tracker); ((CacheItemWatcherBase)Watcher).Start(); } }