2020-03-03 11:18:54 +00:00
|
|
|
|
using System.Web;
|
|
|
|
|
|
using Umbraco.Configuration;
|
2019-11-20 10:20:20 +01:00
|
|
|
|
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;
|
2019-11-20 13:38:41 +01:00
|
|
|
|
using Umbraco.Core.Hosting;
|
2019-11-15 11:07:37 +01:00
|
|
|
|
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;
|
2019-11-11 17:30:50 +11:00
|
|
|
|
using Umbraco.Web.Composing;
|
2018-11-19 21:23:08 +11:00
|
|
|
|
using Umbraco.Web.Logging;
|
2020-01-07 13:08:21 +01:00
|
|
|
|
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>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// <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
|
|
|
|
{
|
2016-08-31 16:48:57 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="WebRuntime"/> class.
|
|
|
|
|
|
/// </summary>
|
2019-12-12 12:55:17 +01:00
|
|
|
|
public WebRuntime(
|
|
|
|
|
|
Configs configs,
|
|
|
|
|
|
IUmbracoVersion umbracoVersion,
|
|
|
|
|
|
IIOHelper ioHelper,
|
|
|
|
|
|
ILogger logger,
|
|
|
|
|
|
IProfiler profiler,
|
|
|
|
|
|
IHostingEnvironment hostingEnvironment,
|
|
|
|
|
|
IBackOfficeInfo backOfficeInfo,
|
|
|
|
|
|
IDbProviderFactoryCreator dbProviderFactoryCreator,
|
2020-01-06 14:59:17 +01:00
|
|
|
|
IMainDom mainDom):
|
2020-01-15 13:40:35 +11:00
|
|
|
|
base(configs, umbracoVersion, ioHelper, logger, profiler ,new AspNetUmbracoBootPermissionChecker(), hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom)
|
2018-11-19 21:23:08 +11:00
|
|
|
|
{
|
2019-11-20 10:20:20 +01:00
|
|
|
|
|
|
|
|
|
|
Profiler = GetWebProfiler();
|
2018-11-19 21:23:08 +11:00
|
|
|
|
}
|
2016-08-31 16:48:57 +02:00
|
|
|
|
|
2019-11-20 10:20:20 +01:00
|
|
|
|
private IProfiler GetWebProfiler()
|
2016-08-25 15:09:51 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
// create and start asap to profile boot
|
2019-11-20 10:20:20 +01:00
|
|
|
|
if (!State.Debug)
|
2016-11-03 10:31:44 +01:00
|
|
|
|
{
|
|
|
|
|
|
// 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
|
2019-11-20 10:20:20 +01:00
|
|
|
|
return new VoidProfiler();
|
2016-11-03 10:31:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-20 10:20:20 +01:00
|
|
|
|
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}'.",
|
2019-11-20 10:20:20 +01:00
|
|
|
|
HostingEnvironment.SiteName,
|
2019-11-20 13:38:41 +01:00
|
|
|
|
HostingEnvironment.ApplicationId,
|
2019-11-20 10:20:20 +01:00
|
|
|
|
HostingEnvironment.ApplicationPhysicalPath,
|
|
|
|
|
|
NetworkHelper.MachineName);
|
|
|
|
|
|
Logger.Debug<CoreRuntime>("Runtime: {Runtime}", GetType().FullName);
|
|
|
|
|
|
|
2020-01-07 13:08:21 +01:00
|
|
|
|
var factory = Current.Factory = base.Boot(register);
|
2019-11-20 10:20:20 +01:00
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
}
|
2016-08-31 16:48:57 +02:00
|
|
|
|
|
2018-11-29 10:35:16 +01:00
|
|
|
|
|
2016-08-25 15:09:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-26 16:54:32 +01:00
|
|
|
|
#region Getters
|
2018-06-12 23:12:44 +02:00
|
|
|
|
|
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
|
2019-11-11 16:07:47 +11:00
|
|
|
|
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)
|
2019-11-11 16:07:47 +11:00
|
|
|
|
new DeepCloneAppCache(new ObjectCacheAppCache(TypeFinder))));
|
2016-08-25 15:09:51 +02:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|