From 681a25b861f632aae867c496de54ee35c0b774ea Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 27 Mar 2020 11:39:17 +0100 Subject: [PATCH] Moved files from backoffice into Common + Introduced AspNetCoreComponent to invoke the Umbraco Application Init event --- .../Net/IUmbracoApplicationLifetime.cs | 2 ++ .../Implementations/TestHelper.cs | 1 + .../Implementations/TestHostingEnvironment.cs | 4 +-- src/Umbraco.Tests.Integration/RuntimeTests.cs | 11 +++---- .../AspNetCoreApplicationShutdownRegistry.cs | 2 +- .../AspNetCore/AspNetCoreBackOfficeInfo.cs | 2 +- .../AspNetCoreHostingEnvironment.cs | 8 ++--- .../AspNetCore/AspNetCoreIpResolver.cs | 2 +- .../AspNetCore/AspNetCoreMarchal.cs | 2 +- .../AspNetCore/AspNetCoreSessionIdResolver.cs | 4 +-- .../AspNetCoreUmbracoApplicationLifetime.cs | 9 +++--- .../UmbracoCoreServiceCollectionExtensions.cs | 8 ++--- .../Lifetime/IUmbracoRequestLifetime.cs | 11 +++++++ .../IUmbracoRequestLifetimeManager.cs | 10 +++++++ .../Lifetime/UmbracoRequestLifetime.cs | 21 ++++++++++++++ .../Middleware/UmbracoRequestMiddleware.cs | 28 +----------------- .../Runtime/AspNetCoreComponent.cs | 29 +++++++++++++++++++ .../Runtime}/AspNetCoreComposer.cs | 15 ++++++++-- .../Runtime/Profiler/WebInitialComponent.cs | 18 ------------ .../Runtime/Profiler/WebInitialComposer.cs | 24 --------------- .../Runtime/Profiler/WebProfiler.cs | 9 ++++-- .../Runtime/Profiler/WebProfilerComponent.cs | 1 + .../Umbraco.Web.Common.csproj | 1 + src/Umbraco.Web.UI.NetCore/Startup.cs | 8 ++++- .../AspNetUmbracoApplicationLifetime.cs | 4 +++ src/Umbraco.Web/Logging/WebProfiler.cs | 2 +- 26 files changed, 134 insertions(+), 102 deletions(-) rename src/{Umbraco.Web.BackOffice => Umbraco.Web.Common}/AspNetCore/AspNetCoreApplicationShutdownRegistry.cs (97%) rename src/{Umbraco.Web.BackOffice => Umbraco.Web.Common}/AspNetCore/AspNetCoreBackOfficeInfo.cs (88%) rename src/{Umbraco.Web.BackOffice => Umbraco.Web.Common}/AspNetCore/AspNetCoreHostingEnvironment.cs (98%) rename src/{Umbraco.Web.BackOffice => Umbraco.Web.Common}/AspNetCore/AspNetCoreIpResolver.cs (91%) rename src/{Umbraco.Web.BackOffice => Umbraco.Web.Common}/AspNetCore/AspNetCoreMarchal.cs (88%) rename src/{Umbraco.Web.BackOffice => Umbraco.Web.Common}/AspNetCore/AspNetCoreSessionIdResolver.cs (94%) rename src/{Umbraco.Web.BackOffice => Umbraco.Web.Common}/AspNetCore/UmbracoCoreServiceCollectionExtensions.cs (97%) create mode 100644 src/Umbraco.Web.Common/Lifetime/IUmbracoRequestLifetime.cs create mode 100644 src/Umbraco.Web.Common/Lifetime/IUmbracoRequestLifetimeManager.cs create mode 100644 src/Umbraco.Web.Common/Lifetime/UmbracoRequestLifetime.cs create mode 100644 src/Umbraco.Web.Common/Runtime/AspNetCoreComponent.cs rename src/{Umbraco.Web.BackOffice/AspNetCore => Umbraco.Web.Common/Runtime}/AspNetCoreComposer.cs (54%) delete mode 100644 src/Umbraco.Web.Common/Runtime/Profiler/WebInitialComponent.cs delete mode 100644 src/Umbraco.Web.Common/Runtime/Profiler/WebInitialComposer.cs diff --git a/src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs b/src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs index 8bf3f115cd..c84d475e90 100644 --- a/src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs +++ b/src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs @@ -15,5 +15,7 @@ namespace Umbraco.Net void Restart(); event EventHandler ApplicationInit; + + void InvokeApplicationInit(); } } diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs index 4a986fa35a..f10586b94b 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Runtime; using Umbraco.Tests.Common; using Umbraco.Web.BackOffice; using Umbraco.Web.BackOffice.AspNetCore; +using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; namespace Umbraco.Tests.Integration.Implementations diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs index 491b7e5480..652aad8928 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs @@ -1,11 +1,11 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Umbraco.Core.Configuration; -using Umbraco.Web.BackOffice.AspNetCore; +using Umbraco.Web.Common.AspNetCore; namespace Umbraco.Tests.Integration.Implementations { - + public class TestHostingEnvironment : AspNetCoreHostingEnvironment, Umbraco.Core.Hosting.IHostingEnvironment { public TestHostingEnvironment(IHostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContextAccessor) : base(hostingSettings, webHostEnvironment, httpContextAccessor) diff --git a/src/Umbraco.Tests.Integration/RuntimeTests.cs b/src/Umbraco.Tests.Integration/RuntimeTests.cs index 0e11a29b95..c7bb22f135 100644 --- a/src/Umbraco.Tests.Integration/RuntimeTests.cs +++ b/src/Umbraco.Tests.Integration/RuntimeTests.cs @@ -22,6 +22,7 @@ using Umbraco.Tests.Common; using Umbraco.Tests.Integration.Implementations; using Umbraco.Tests.Integration.Testing; using Umbraco.Web.BackOffice.AspNetCore; +using Umbraco.Web.Common.AspNetCore; using static Umbraco.Core.Migrations.Install.DatabaseBuilder; namespace Umbraco.Tests.Integration @@ -52,11 +53,11 @@ namespace Umbraco.Tests.Integration // LightInject / Umbraco var container = UmbracoServiceProviderFactory.CreateServiceContainer(); var serviceProviderFactory = new UmbracoServiceProviderFactory(container); - var umbracoContainer = serviceProviderFactory.GetContainer(); + var umbracoContainer = serviceProviderFactory.GetContainer(); // Special case since we are not using the Generic Host, we need to manually add an AspNetCore service to the container umbracoContainer.Register(x => Mock.Of()); - + var testHelper = new TestHelper(); // Create the core runtime @@ -70,7 +71,7 @@ namespace Umbraco.Tests.Integration Assert.IsTrue(coreRuntime.MainDom.IsMainDom); Assert.IsNull(coreRuntime.State.BootFailedException); - Assert.AreEqual(RuntimeLevel.Install, coreRuntime.State.Level); + Assert.AreEqual(RuntimeLevel.Install, coreRuntime.State.Level); Assert.IsTrue(MyComposer.IsComposed); Assert.IsFalse(MyComponent.IsInit); Assert.IsFalse(MyComponent.IsTerminated); @@ -88,7 +89,7 @@ namespace Umbraco.Tests.Integration } /// - /// Calling AddUmbracoCore to configure the container + /// Calling AddUmbracoCore to configure the container /// [Test] public async Task AddUmbracoCore() @@ -280,5 +281,5 @@ namespace Umbraco.Tests.Integration } } - + } diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreApplicationShutdownRegistry.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreApplicationShutdownRegistry.cs similarity index 97% rename from src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreApplicationShutdownRegistry.cs rename to src/Umbraco.Web.Common/AspNetCore/AspNetCoreApplicationShutdownRegistry.cs index 92af822836..57ad83d4ba 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreApplicationShutdownRegistry.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreApplicationShutdownRegistry.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Hosting; using Umbraco.Core; using Umbraco.Core.Hosting; -namespace Umbraco.Web.BackOffice.AspNetCore +namespace Umbraco.Web.Common.AspNetCore { public class AspNetCoreApplicationShutdownRegistry : IApplicationShutdownRegistry { diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreBackOfficeInfo.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs similarity index 88% rename from src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreBackOfficeInfo.cs rename to src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs index ba12b64dfe..375028132e 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreBackOfficeInfo.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs @@ -1,7 +1,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; -namespace Umbraco.Web.BackOffice.AspNetCore +namespace Umbraco.Web.Common.AspNetCore { public class AspNetCoreBackOfficeInfo : IBackOfficeInfo { diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs similarity index 98% rename from src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs rename to src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index 6f1298918d..c24c2c4698 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -6,16 +6,16 @@ using Microsoft.AspNetCore.Http; using Umbraco.Core; using Umbraco.Core.Configuration; -namespace Umbraco.Web.BackOffice.AspNetCore +namespace Umbraco.Web.Common.AspNetCore { public class AspNetCoreHostingEnvironment : Umbraco.Core.Hosting.IHostingEnvironment { - + private readonly IHostingSettings _hostingSettings; private readonly IWebHostEnvironment _webHostEnvironment; private readonly IHttpContextAccessor _httpContextAccessor; - + private string _localTempPath; public AspNetCoreHostingEnvironment(IHostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContextAccessor) @@ -103,7 +103,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore return applicationPath.Add(segment).Value; } - + } diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreIpResolver.cs similarity index 91% rename from src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs rename to src/Umbraco.Web.Common/AspNetCore/AspNetCoreIpResolver.cs index cee43757d8..863d545066 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreIpResolver.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Http; using Umbraco.Net; -namespace Umbraco.Web.BackOffice.AspNetCore +namespace Umbraco.Web.Common.AspNetCore { public class AspNetIpResolver : IIpResolver { diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreMarchal.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreMarchal.cs similarity index 88% rename from src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreMarchal.cs rename to src/Umbraco.Web.Common/AspNetCore/AspNetCoreMarchal.cs index 247666090e..af23d092e9 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreMarchal.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreMarchal.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; using Umbraco.Core.Diagnostics; -namespace Umbraco.Web.BackOffice.AspNetCore +namespace Umbraco.Web.Common.AspNetCore { public class AspNetCoreMarchal : IMarchal diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreSessionIdResolver.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreSessionIdResolver.cs similarity index 94% rename from src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreSessionIdResolver.cs rename to src/Umbraco.Web.Common/AspNetCore/AspNetCoreSessionIdResolver.cs index cafb02d367..818a39fac5 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreSessionIdResolver.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreSessionIdResolver.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Http.Features; using Umbraco.Net; -namespace Umbraco.Web.BackOffice.AspNetCore +namespace Umbraco.Web.Common.AspNetCore { internal class AspNetCoreSessionIdResolver : ISessionIdResolver { @@ -13,7 +13,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore _httpContextAccessor = httpContextAccessor; } - + public string SessionId { get diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreUmbracoApplicationLifetime.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreUmbracoApplicationLifetime.cs index 45cfb7d570..d73b9bebd4 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreUmbracoApplicationLifetime.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreUmbracoApplicationLifetime.cs @@ -15,11 +15,6 @@ namespace Umbraco.Web.Common.AspNetCore { _httpContextAccessor = httpContextAccessor; _hostApplicationLifetime = hostApplicationLifetime; - - hostApplicationLifetime.ApplicationStarted.Register(() => - { - ApplicationInit?.Invoke(this, EventArgs.Empty); - }); } public bool IsRestarting { get; set; } @@ -39,6 +34,10 @@ namespace Umbraco.Web.Common.AspNetCore _hostApplicationLifetime.StopApplication(); } + public void InvokeApplicationInit() + { + ApplicationInit?.Invoke(this, EventArgs.Empty); + } public event EventHandler ApplicationInit; } } diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/AspNetCore/UmbracoCoreServiceCollectionExtensions.cs similarity index 97% rename from src/Umbraco.Web.BackOffice/AspNetCore/UmbracoCoreServiceCollectionExtensions.cs rename to src/Umbraco.Web.Common/AspNetCore/UmbracoCoreServiceCollectionExtensions.cs index c14b164e9c..eb320c459f 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/AspNetCore/UmbracoCoreServiceCollectionExtensions.cs @@ -19,9 +19,8 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Runtime; using Umbraco.Web.Common.Runtime.Profiler; -namespace Umbraco.Web.BackOffice.AspNetCore +namespace Umbraco.Web.Common.AspNetCore { - // TODO: Move to Umbraco.Web.Common public static class UmbracoCoreServiceCollectionExtensions { /// @@ -71,7 +70,8 @@ namespace Umbraco.Web.BackOffice.AspNetCore public static IServiceCollection AddUmbracoCore(this IServiceCollection services, IWebHostEnvironment webHostEnvironment, IRegister umbContainer, Assembly entryAssembly) { if (services is null) throw new ArgumentNullException(nameof(services)); - if (umbContainer is null) throw new ArgumentNullException(nameof(umbContainer)); + var container = umbContainer; + if (container is null) throw new ArgumentNullException(nameof(container)); if (entryAssembly is null) throw new ArgumentNullException(nameof(entryAssembly)); // Special case! The generic host adds a few default services but we need to manually add this one here NOW because @@ -97,7 +97,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore backOfficeInfo, typeFinder); - var factory = coreRuntime.Configure(umbContainer); + var factory = coreRuntime.Configure(container); return services; } diff --git a/src/Umbraco.Web.Common/Lifetime/IUmbracoRequestLifetime.cs b/src/Umbraco.Web.Common/Lifetime/IUmbracoRequestLifetime.cs new file mode 100644 index 0000000000..616a75bfe7 --- /dev/null +++ b/src/Umbraco.Web.Common/Lifetime/IUmbracoRequestLifetime.cs @@ -0,0 +1,11 @@ +using System; +using Microsoft.AspNetCore.Http; + +namespace Umbraco.Web.Common.Lifetime +{ + public interface IUmbracoRequestLifetime + { + event EventHandler RequestStart; + event EventHandler RequestEnd; + } +} diff --git a/src/Umbraco.Web.Common/Lifetime/IUmbracoRequestLifetimeManager.cs b/src/Umbraco.Web.Common/Lifetime/IUmbracoRequestLifetimeManager.cs new file mode 100644 index 0000000000..e4c671c2d3 --- /dev/null +++ b/src/Umbraco.Web.Common/Lifetime/IUmbracoRequestLifetimeManager.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Http; + +namespace Umbraco.Web.Common.Lifetime +{ + public interface IUmbracoRequestLifetimeManager + { + void InitRequest(HttpContext context); + void EndRequest(HttpContext context); + } +} diff --git a/src/Umbraco.Web.Common/Lifetime/UmbracoRequestLifetime.cs b/src/Umbraco.Web.Common/Lifetime/UmbracoRequestLifetime.cs new file mode 100644 index 0000000000..43810a9e66 --- /dev/null +++ b/src/Umbraco.Web.Common/Lifetime/UmbracoRequestLifetime.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.AspNetCore.Http; + +namespace Umbraco.Web.Common.Lifetime +{ + public class UmbracoRequestLifetime : IUmbracoRequestLifetime, IUmbracoRequestLifetimeManager + { + public event EventHandler RequestStart; + public event EventHandler RequestEnd; + + public void InitRequest(HttpContext context) + { + RequestStart?.Invoke(this, context); + } + + public void EndRequest(HttpContext context) + { + RequestEnd?.Invoke(this, context); + } + } +} diff --git a/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs b/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs index 60b6463152..93461fc1d5 100644 --- a/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs +++ b/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Umbraco.Web.Common.Lifetime; namespace Umbraco.Web.Common.Middleware { @@ -22,31 +23,4 @@ namespace Umbraco.Web.Common.Middleware } } - public interface IUmbracoRequestLifetime - { - event EventHandler RequestStart; - event EventHandler RequestEnd; - } - - public class UmbracoRequestLifetime : IUmbracoRequestLifetime, IUmbracoRequestLifetimeManager - { - public event EventHandler RequestStart; - public event EventHandler RequestEnd; - - public void InitRequest(HttpContext context) - { - RequestStart?.Invoke(this, context); - } - - public void EndRequest(HttpContext context) - { - RequestEnd?.Invoke(this, context); - } - } - - public interface IUmbracoRequestLifetimeManager - { - void InitRequest(HttpContext context); - void EndRequest(HttpContext context); - } } diff --git a/src/Umbraco.Web.Common/Runtime/AspNetCoreComponent.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreComponent.cs new file mode 100644 index 0000000000..04ae022fa5 --- /dev/null +++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreComponent.cs @@ -0,0 +1,29 @@ +using Microsoft.Extensions.Hosting; +using Umbraco.Core.Composing; +using Umbraco.Net; + +namespace Umbraco.Web.Common.Runtime +{ + public sealed class AspNetCoreComponent : IComponent + { + private readonly IHostApplicationLifetime _hostApplicationLifetime; + private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime; + + public AspNetCoreComponent(IHostApplicationLifetime hostApplicationLifetime, IUmbracoApplicationLifetime umbracoApplicationLifetime) + { + _hostApplicationLifetime = hostApplicationLifetime; + _umbracoApplicationLifetime = umbracoApplicationLifetime; + } + + public void Initialize() + { + _hostApplicationLifetime.ApplicationStarted.Register(() => { + _umbracoApplicationLifetime.InvokeApplicationInit(); + }); + } + + public void Terminate() + { + } + } +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreComposer.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs similarity index 54% rename from src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreComposer.cs rename to src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs index 463af87849..f9a6a770e2 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreComposer.cs +++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs @@ -5,24 +5,33 @@ using Umbraco.Core.Hosting; using Umbraco.Net; using Umbraco.Core.Runtime; using Umbraco.Web.Common.AspNetCore; +using Umbraco.Web.Common.Lifetime; -namespace Umbraco.Web.BackOffice.AspNetCore +namespace Umbraco.Web.Common.Runtime { /// /// Adds/replaces AspNetCore specific services /// [ComposeBefore(typeof(ICoreComposer))] [ComposeAfter(typeof(CoreInitialComposer))] - public class AspNetCoreComposer : IComposer + public class AspNetCoreComposer : ComponentComposer, IComposer { - public void Compose(Composition composition) + public new void Compose(Composition composition) { + base.Compose(composition); + // AspNetCore specific services composition.RegisterUnique(); // Our own netcore implementations composition.RegisterUnique(); composition.RegisterUnique(); + + // The umbraco request lifetime + var umbracoRequestLifetime = new UmbracoRequestLifetime(); + composition.RegisterUnique(factory => umbracoRequestLifetime); + composition.RegisterUnique(factory => umbracoRequestLifetime); + composition.RegisterUnique(); } } } diff --git a/src/Umbraco.Web.Common/Runtime/Profiler/WebInitialComponent.cs b/src/Umbraco.Web.Common/Runtime/Profiler/WebInitialComponent.cs deleted file mode 100644 index 2194b3c038..0000000000 --- a/src/Umbraco.Web.Common/Runtime/Profiler/WebInitialComponent.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Umbraco.Core.Composing; - -namespace Umbraco.Web.Common.Runtime.Profiler -{ - public sealed class WebInitialComponent : IComponent - { - - - public void Initialize() - { - } - - public void Terminate() - { - } - - } -} diff --git a/src/Umbraco.Web.Common/Runtime/Profiler/WebInitialComposer.cs b/src/Umbraco.Web.Common/Runtime/Profiler/WebInitialComposer.cs deleted file mode 100644 index 472d8bf8e9..0000000000 --- a/src/Umbraco.Web.Common/Runtime/Profiler/WebInitialComposer.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Umbraco.Core; -using Umbraco.Core.Composing; -using Umbraco.Net; -using Umbraco.Web.Common.AspNetCore; -using Umbraco.Web.Common.Middleware; - -namespace Umbraco.Web.Common.Runtime.Profiler -{ - public class WebInitialComposer : ComponentComposer, ICoreComposer - { - - public override void Compose(Composition composition) - { - base.Compose(composition); - - var umbracoRequestLifetime = new UmbracoRequestLifetime(); - - composition.RegisterUnique(factory => umbracoRequestLifetime); - composition.RegisterUnique(factory => umbracoRequestLifetime); - composition.RegisterUnique(); - } - } -} diff --git a/src/Umbraco.Web.Common/Runtime/Profiler/WebProfiler.cs b/src/Umbraco.Web.Common/Runtime/Profiler/WebProfiler.cs index 4e1a7c7d84..8baf8790c3 100644 --- a/src/Umbraco.Web.Common/Runtime/Profiler/WebProfiler.cs +++ b/src/Umbraco.Web.Common/Runtime/Profiler/WebProfiler.cs @@ -22,10 +22,15 @@ namespace Umbraco.Web.Common.Runtime.Profiler // create our own provider, which can provide a profiler even during boot _provider = new WebProfilerProvider(); _httpContextAccessor = httpContextAccessor; + + MiniProfiler.DefaultOptions.ProfilerProvider = _provider; } - public string Render() => MiniProfiler.Current - .RenderIncludes(_httpContextAccessor.HttpContext, RenderPosition.Right).ToString(); + public string Render() + { + return MiniProfiler.Current + .RenderIncludes(_httpContextAccessor.HttpContext, RenderPosition.Right).ToString(); + } public IDisposable Step(string name) => MiniProfiler.Current?.Step(name); diff --git a/src/Umbraco.Web.Common/Runtime/Profiler/WebProfilerComponent.cs b/src/Umbraco.Web.Common/Runtime/Profiler/WebProfilerComponent.cs index 425996a765..9a656ae4f3 100644 --- a/src/Umbraco.Web.Common/Runtime/Profiler/WebProfilerComponent.cs +++ b/src/Umbraco.Web.Common/Runtime/Profiler/WebProfilerComponent.cs @@ -2,6 +2,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Net; +using Umbraco.Web.Common.Lifetime; using Umbraco.Web.Common.Middleware; namespace Umbraco.Web.Common.Runtime.Profiler diff --git a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj index cb9ca9156a..2cf6790484 100644 --- a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj +++ b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj @@ -11,6 +11,7 @@ + diff --git a/src/Umbraco.Web.UI.NetCore/Startup.cs b/src/Umbraco.Web.UI.NetCore/Startup.cs index fe77dfabda..b38333bb9a 100644 --- a/src/Umbraco.Web.UI.NetCore/Startup.cs +++ b/src/Umbraco.Web.UI.NetCore/Startup.cs @@ -8,7 +8,9 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Umbraco.Composing; using Umbraco.Web.BackOffice.AspNetCore; +using Umbraco.Web.Common.AspNetCore; using Umbraco.Web.Common.Extensions; using Umbraco.Web.Website.AspNetCore; @@ -52,6 +54,7 @@ namespace Umbraco.Web.UI.BackOffice app.UseDeveloperExceptionPage(); } + app.UseUmbracoCore(); app.UseUmbracoWebsite(); app.UseUmbracoBackOffice(); @@ -59,7 +62,10 @@ namespace Umbraco.Web.UI.BackOffice app.UseEndpoints(endpoints => { - endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); + endpoints.MapGet("/", async context => + { + await context.Response.WriteAsync($"Hello World!{Current.Profiler.Render()}"); + }); }); } } diff --git a/src/Umbraco.Web/AspNet/AspNetUmbracoApplicationLifetime.cs b/src/Umbraco.Web/AspNet/AspNetUmbracoApplicationLifetime.cs index f5ebc03cd0..9818a510b2 100644 --- a/src/Umbraco.Web/AspNet/AspNetUmbracoApplicationLifetime.cs +++ b/src/Umbraco.Web/AspNet/AspNetUmbracoApplicationLifetime.cs @@ -35,5 +35,9 @@ namespace Umbraco.Web.AspNet } public event EventHandler ApplicationInit; + public void InvokeApplicationInit() + { + + } } } diff --git a/src/Umbraco.Web/Logging/WebProfiler.cs b/src/Umbraco.Web/Logging/WebProfiler.cs index 512edb2296..e390950c0b 100755 --- a/src/Umbraco.Web/Logging/WebProfiler.cs +++ b/src/Umbraco.Web/Logging/WebProfiler.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.Logging MiniProfiler.Configure(new MiniProfilerOptions { SqlFormatter = new SqlServerFormatter(), - StackMaxLength = 5000, + StackMaxLength = 5000, ProfilerProvider = _provider }); }