From c3fcbc0a72167de0920f40c534cf1d79cd2c8a9b Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 27 Feb 2020 11:13:57 +0100 Subject: [PATCH] Moved functionality from HostingEnvironment into IUmbracoApplicationLifetime, to not have duplicated logic --- src/Umbraco.Core/Hosting/IHostingEnvironment.cs | 5 ----- src/Umbraco.Core/Manifest/ManifestWatcher.cs | 9 +++++---- src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs | 6 ++++++ .../Compose/ManifestWatcherComponent.cs | 9 +++++---- src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs | 5 ----- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Core/Hosting/IHostingEnvironment.cs b/src/Umbraco.Core/Hosting/IHostingEnvironment.cs index 1662879cf2..41560292c7 100644 --- a/src/Umbraco.Core/Hosting/IHostingEnvironment.cs +++ b/src/Umbraco.Core/Hosting/IHostingEnvironment.cs @@ -22,11 +22,6 @@ namespace Umbraco.Core.Hosting string MapPath(string path); string ToAbsolute(string virtualPath, string root); - /// - /// Terminates the current application. The application restarts the next time a request is received for it. - /// - void LazyRestartApplication(); - void RegisterObject(IRegisteredObject registeredObject); void UnregisterObject(IRegisteredObject registeredObject); } diff --git a/src/Umbraco.Core/Manifest/ManifestWatcher.cs b/src/Umbraco.Core/Manifest/ManifestWatcher.cs index 8d81ac3de5..23caac3a1b 100644 --- a/src/Umbraco.Core/Manifest/ManifestWatcher.cs +++ b/src/Umbraco.Core/Manifest/ManifestWatcher.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using Umbraco.Core.Hosting; using Umbraco.Core.Logging; +using Umbraco.Net; namespace Umbraco.Core.Manifest { @@ -13,13 +14,13 @@ namespace Umbraco.Core.Manifest private static volatile bool _isRestarting; private readonly ILogger _logger; - private readonly IHostingEnvironment _hostingEnvironment; + private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime; private readonly List _fws = new List(); - public ManifestWatcher(ILogger logger, IHostingEnvironment hostingEnvironment) + public ManifestWatcher(ILogger logger, IUmbracoApplicationLifetime umbracoApplicationLifetime) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _hostingEnvironment = hostingEnvironment; + _umbracoApplicationLifetime = umbracoApplicationLifetime; } public void Start(params string[] packageFolders) @@ -57,7 +58,7 @@ namespace Umbraco.Core.Manifest _isRestarting = true; _logger.Info("Manifest has changed, app pool is restarting ({Path})", e.FullPath); - _hostingEnvironment.LazyRestartApplication(); + _umbracoApplicationLifetime.Restart(); Dispose(); // uh? if the app restarts then this should be disposed anyways? } } diff --git a/src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs b/src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs index 9723d116bd..10d5b10955 100644 --- a/src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs +++ b/src/Umbraco.Core/Net/IUmbracoApplicationLifetime.cs @@ -2,7 +2,13 @@ namespace Umbraco.Net { public interface IUmbracoApplicationLifetime { + /// + /// A value indicating whether the application is restarting after the current request. + /// bool IsRestarting { get; } + /// + /// Terminates the current application. The application restarts the next time a request is received for it. + /// void Restart(); } } diff --git a/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs b/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs index 334183a48c..d4e22bbfde 100644 --- a/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs @@ -4,6 +4,7 @@ using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; +using Umbraco.Net; namespace Umbraco.Core.Compose { @@ -12,18 +13,18 @@ namespace Umbraco.Core.Compose private readonly IRuntimeState _runtimeState; private readonly ILogger _logger; private readonly IIOHelper _ioHelper; - private readonly IHostingEnvironment _hostingEnvironment; + private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime; // if configured and in debug mode, a ManifestWatcher watches App_Plugins folders for // package.manifest chances and restarts the application on any change private ManifestWatcher _mw; - public ManifestWatcherComponent(IRuntimeState runtimeState, ILogger logger, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment) + public ManifestWatcherComponent(IRuntimeState runtimeState, ILogger logger, IIOHelper ioHelper, IUmbracoApplicationLifetime umbracoApplicationLifetime) { _runtimeState = runtimeState; _logger = logger; _ioHelper = ioHelper; - _hostingEnvironment = hostingEnvironment; + _umbracoApplicationLifetime = umbracoApplicationLifetime; } public void Initialize() @@ -36,7 +37,7 @@ namespace Umbraco.Core.Compose var appPlugins = _ioHelper.MapPath("~/App_Plugins/"); if (Directory.Exists(appPlugins) == false) return; - _mw = new ManifestWatcher(_logger, _hostingEnvironment); + _mw = new ManifestWatcher(_logger, _umbracoApplicationLifetime); _mw.Start(Directory.GetDirectories(appPlugins)); } diff --git a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs index f9b1f1019b..75c4bcb660 100644 --- a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs @@ -49,11 +49,6 @@ namespace Umbraco.Web.Hosting } public string ToAbsolute(string virtualPath, string root) => VirtualPathUtility.ToAbsolute(virtualPath, root); - public void LazyRestartApplication() - { - HttpRuntime.UnloadAppDomain(); - } - public void RegisterObject(IRegisteredObject registeredObject) { var wrapped = new RegisteredObjectWrapper(registeredObject);