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

98 lines
4.0 KiB
C#
Raw Normal View History

2016-08-25 15:09:51 +02:00
using System;
using System.Web;
using LightInject;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
2017-05-30 15:46:25 +02:00
using Umbraco.Core.Composing;
2016-08-25 15:09:51 +02:00
using Umbraco.Core.Persistence;
namespace Umbraco.Web
{
/// <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
{
private IProfiler _webProfiler;
/// <summary>
/// Initializes a new instance of the <see cref="WebRuntime"/> class.
/// </summary>
/// <param name="umbracoApplication"></param>
public WebRuntime(UmbracoApplicationBase umbracoApplication)
: base(umbracoApplication)
{ }
/// <inheritdoc/>
2016-08-25 15:09:51 +02:00
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();
}
2016-08-25 15:09:51 +02:00
base.Boot(container);
// now (and only now) is the time to switch over to perWebRequest scopes
2017-05-12 14:49:44 +02:00
var smp = container.ScopeManagerProvider as MixedLightInjectScopeManagerProvider;
if (smp == null) throw new Exception("Container.ScopeManagerProvider is not MixedLightInjectScopeManagerProvider.");
smp.EnablePerWebRequestScope();
2016-08-25 15:09:51 +02:00
}
/// <inheritdoc/>
public override void Compose(ServiceContainer container)
2016-08-25 15:09:51 +02:00
{
base.Compose(container);
2016-08-25 15:09:51 +02:00
// replace CoreRuntime's IProfiler registration
container.RegisterSingleton<IProfiler>(_ => _webProfiler);
2016-08-25 15:09:51 +02:00
// replace CoreRuntime's CacheHelper registration
container.RegisterSingleton(_ => new CacheHelper(
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 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()))));
2016-08-25 15:09:51 +02:00
container.RegisterSingleton<IHttpContextAccessor, AspNetHttpContextAccessor>(); // required for hybrid accessors
2016-08-25 15:09:51 +02:00
}
#region Getters
2016-08-25 15:09:51 +02:00
//protected override IProfiler GetProfiler() => new WebProfiler();
2016-08-25 15:09:51 +02:00
//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())));
2016-08-25 15:09:51 +02:00
#endregion
}
}