using System.Web; using Umbraco.Configuration; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Runtime; using Umbraco.Web.Composing; using Umbraco.Web.Logging; using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Web.Runtime { /// /// Represents the Web Umbraco runtime. /// /// On top of CoreRuntime, handles all of the web-related runtime aspects of Umbraco. public class WebRuntime : CoreRuntime { /// /// Initializes a new instance of the class. /// public WebRuntime( Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo, IDbProviderFactoryCreator dbProviderFactoryCreator, IMainDom mainDom): base(configs, umbracoVersion, ioHelper, logger, profiler ,new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom) { Profiler = GetWebProfiler(); } private IProfiler GetWebProfiler() { // create and start asap to profile boot if (!State.Debug) { // 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 return new VoidProfiler(); } var webProfiler = new WebProfiler(); webProfiler.Start(); return webProfiler; } /// public override IFactory Boot(IRegister register) { var profilingLogger = new ProfilingLogger(Logger, Profiler); var umbracoVersion = new UmbracoVersion(); using (var timer = profilingLogger.TraceDuration( $"Booting Umbraco {umbracoVersion.SemanticVersion.ToSemanticString()}.", "Booted.", "Boot failed.")) { Logger.Info("Booting site '{HostingSiteName}', app '{HostingApplicationId}', path '{HostingPhysicalPath}', server '{MachineName}'.", HostingEnvironment.SiteName, HostingEnvironment.ApplicationId, HostingEnvironment.ApplicationPhysicalPath, NetworkHelper.MachineName); Logger.Debug("Runtime: {Runtime}", GetType().FullName); var factory = Current.Factory = base.Boot(register); // now (and only now) is the time to switch over to perWebRequest scopes. // up until that point we may not have a request, and scoped services would // fail to resolve - but we run Initialize within a factory scope - and then, // here, we switch the factory to bind scopes to requests factory.EnablePerWebRequestScope(); return factory; } } #region Getters protected override AppCaches GetAppCaches() => new AppCaches( // we need to have the dep clone runtime cache provider to ensure // all entities are cached properly (cloned in and cloned out) new DeepCloneAppCache(new ObjectCacheAppCache(TypeFinder)), // we need request based cache when running in web-based context new HttpRequestAppCache(() => HttpContext.Current?.Items, TypeFinder), new IsolatedCaches(type => // we need to have the dep clone runtime cache provider to ensure // all entities are cached properly (cloned in and cloned out) new DeepCloneAppCache(new ObjectCacheAppCache(TypeFinder)))); #endregion } }