Files
Umbraco-CMS/src/Umbraco.Web/Runtime/WebRuntime.cs

108 lines
4.1 KiB
C#
Raw Normal View History

using System.Web;
using Umbraco.Configuration;
using Umbraco.Core;
2016-08-25 15:09:51 +02:00
using Umbraco.Core.Cache;
2017-05-30 15:46:25 +02:00
using Umbraco.Core.Composing;
2017-12-28 09:27:57 +01:00
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
2017-12-28 09:27:57 +01:00
using Umbraco.Core.Logging;
2019-12-12 08:11:23 +01:00
using Umbraco.Core.Persistence;
2017-12-28 09:27:57 +01:00
using Umbraco.Core.Runtime;
using Umbraco.Web.Composing;
using Umbraco.Web.Logging;
using Current = Umbraco.Web.Composing.Current;
2016-08-25 15:09:51 +02:00
2017-12-28 09:27:57 +01:00
namespace Umbraco.Web.Runtime
2016-08-25 15:09:51 +02:00
{
/// <summary>
/// Represents the Web Umbraco runtime.
/// </summary>
/// <remarks>On top of CoreRuntime, handles all of the web-related runtime aspects of Umbraco.</remarks>
public class WebRuntime : CoreRuntime
2016-08-25 15:09:51 +02:00
{
/// <summary>
/// Initializes a new instance of the <see cref="WebRuntime"/> class.
/// </summary>
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()
2016-08-25 15:09:51 +02:00
{
// 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;
}
/// <inheritdoc/>
public override IFactory Boot(IRegister register)
{
var profilingLogger = new ProfilingLogger(Logger, Profiler);
var umbracoVersion = new UmbracoVersion();
using (var timer = profilingLogger.TraceDuration<CoreRuntime>(
$"Booting Umbraco {umbracoVersion.SemanticVersion.ToSemanticString()}.",
"Booted.",
"Boot failed."))
{
2019-11-20 15:21:09 +01:00
Logger.Info<CoreRuntime>("Booting site '{HostingSiteName}', app '{HostingApplicationId}', path '{HostingPhysicalPath}', server '{MachineName}'.",
HostingEnvironment.SiteName,
HostingEnvironment.ApplicationId,
HostingEnvironment.ApplicationPhysicalPath,
NetworkHelper.MachineName);
Logger.Debug<CoreRuntime>("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;
}
2018-11-29 10:35:16 +01:00
2016-08-25 15:09:51 +02:00
}
#region Getters
2019-01-17 08:34:29 +01:00
protected override AppCaches GetAppCaches() => new AppCaches(
2016-08-25 15:09:51 +02:00
// we need to have the dep clone runtime cache provider to ensure
// all entities are cached properly (cloned in and cloned out)
2020-03-03 07:29:51 +01:00
new DeepCloneAppCache(new ObjectCacheAppCache(TypeFinder)),
2016-08-25 15:09:51 +02:00
// we need request based cache when running in web-based context
new HttpRequestAppCache(() => HttpContext.Current?.Items, TypeFinder),
2019-01-17 11:01:23 +01:00
new IsolatedCaches(type =>
2016-08-25 15:09:51 +02:00
// 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))));
2016-08-25 15:09:51 +02:00
#endregion
}
}