using System; using System.Web; using LightInject; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Composing; using Umbraco.Core.Persistence; namespace Umbraco.Web { /// /// Represents the Web Umbraco runtime. /// /// On top of CoreRuntime, handles all of the web-related runtime aspects of Umbraco. public class WebRuntime : CoreRuntime { private IProfiler _webProfiler; /// /// Initializes a new instance of the class. /// /// public WebRuntime(UmbracoApplicationBase umbracoApplication) : base(umbracoApplication) { } /// public override void Boot(ServiceContainer container) { // create and start asap to profile boot var debug = GlobalSettings.DebugMode; if (debug) { _webProfiler = new WebProfiler(); _webProfiler.Start(); } else { // should let it be null, that's how MiniProfiler is meant to work, // but our own IProfiler expects an instance so let's get one _webProfiler = new VoidProfiler(); } base.Boot(container); // now (and only now) is the time to switch over to perWebRequest scopes var smp = container.ScopeManagerProvider as MixedLightInjectScopeManagerProvider; if (smp == null) throw new Exception("Container.ScopeManagerProvider is not MixedLightInjectScopeManagerProvider."); smp.EnablePerWebRequestScope(); } /// public override void Compose(ServiceContainer container) { base.Compose(container); // replace CoreRuntime's IProfiler registration container.RegisterSingleton(_ => _webProfiler); // replace CoreRuntime's CacheHelper registration container.RegisterSingleton(_ => new CacheHelper( // we need to have the dep clone runtime cache provider to ensure // all entities are cached properly (cloned in and cloned out) new DeepCloneRuntimeCacheProvider(new HttpRuntimeCacheProvider(HttpRuntime.Cache)), new StaticCacheProvider(), // we need request based cache when running in web-based context new HttpRequestCacheProvider(), new IsolatedRuntimeCache(type => // we need to have the dep clone runtime cache provider to ensure // all entities are cached properly (cloned in and cloned out) new DeepCloneRuntimeCacheProvider(new ObjectCacheRuntimeCacheProvider())))); container.RegisterSingleton(); // required for hybrid accessors } #region Getters //protected override IProfiler GetProfiler() => new WebProfiler(); //protected override CacheHelper GetApplicationCache() => new CacheHelper( // // we need to have the dep clone runtime cache provider to ensure // // all entities are cached properly (cloned in and cloned out) // new DeepCloneRuntimeCacheProvider(new HttpRuntimeCacheProvider(HttpRuntime.Cache)), // new StaticCacheProvider(), // // we need request based cache when running in web-based context // new HttpRequestCacheProvider(), // new IsolatedRuntimeCache(type => // // we need to have the dep clone runtime cache provider to ensure // // all entities are cached properly (cloned in and cloned out) // new DeepCloneRuntimeCacheProvider(new ObjectCacheRuntimeCacheProvider()))); #endregion } }