Moved functionality from HostingEnvironment into IUmbracoApplicationLifetime, to not have duplicated logic
This commit is contained in:
@@ -22,11 +22,6 @@ namespace Umbraco.Core.Hosting
|
|||||||
string MapPath(string path);
|
string MapPath(string path);
|
||||||
string ToAbsolute(string virtualPath, string root);
|
string ToAbsolute(string virtualPath, string root);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Terminates the current application. The application restarts the next time a request is received for it.
|
|
||||||
/// </summary>
|
|
||||||
void LazyRestartApplication();
|
|
||||||
|
|
||||||
void RegisterObject(IRegisteredObject registeredObject);
|
void RegisterObject(IRegisteredObject registeredObject);
|
||||||
void UnregisterObject(IRegisteredObject registeredObject);
|
void UnregisterObject(IRegisteredObject registeredObject);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Umbraco.Core.Hosting;
|
using Umbraco.Core.Hosting;
|
||||||
using Umbraco.Core.Logging;
|
using Umbraco.Core.Logging;
|
||||||
|
using Umbraco.Net;
|
||||||
|
|
||||||
namespace Umbraco.Core.Manifest
|
namespace Umbraco.Core.Manifest
|
||||||
{
|
{
|
||||||
@@ -13,13 +14,13 @@ namespace Umbraco.Core.Manifest
|
|||||||
private static volatile bool _isRestarting;
|
private static volatile bool _isRestarting;
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IHostingEnvironment _hostingEnvironment;
|
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
|
||||||
private readonly List<FileSystemWatcher> _fws = new List<FileSystemWatcher>();
|
private readonly List<FileSystemWatcher> _fws = new List<FileSystemWatcher>();
|
||||||
|
|
||||||
public ManifestWatcher(ILogger logger, IHostingEnvironment hostingEnvironment)
|
public ManifestWatcher(ILogger logger, IUmbracoApplicationLifetime umbracoApplicationLifetime)
|
||||||
{
|
{
|
||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
_hostingEnvironment = hostingEnvironment;
|
_umbracoApplicationLifetime = umbracoApplicationLifetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start(params string[] packageFolders)
|
public void Start(params string[] packageFolders)
|
||||||
@@ -57,7 +58,7 @@ namespace Umbraco.Core.Manifest
|
|||||||
|
|
||||||
_isRestarting = true;
|
_isRestarting = true;
|
||||||
_logger.Info<ManifestWatcher>("Manifest has changed, app pool is restarting ({Path})", e.FullPath);
|
_logger.Info<ManifestWatcher>("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?
|
Dispose(); // uh? if the app restarts then this should be disposed anyways?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ namespace Umbraco.Net
|
|||||||
{
|
{
|
||||||
public interface IUmbracoApplicationLifetime
|
public interface IUmbracoApplicationLifetime
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A value indicating whether the application is restarting after the current request.
|
||||||
|
/// </summary>
|
||||||
bool IsRestarting { get; }
|
bool IsRestarting { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Terminates the current application. The application restarts the next time a request is received for it.
|
||||||
|
/// </summary>
|
||||||
void Restart();
|
void Restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Umbraco.Core.Hosting;
|
|||||||
using Umbraco.Core.IO;
|
using Umbraco.Core.IO;
|
||||||
using Umbraco.Core.Logging;
|
using Umbraco.Core.Logging;
|
||||||
using Umbraco.Core.Manifest;
|
using Umbraco.Core.Manifest;
|
||||||
|
using Umbraco.Net;
|
||||||
|
|
||||||
namespace Umbraco.Core.Compose
|
namespace Umbraco.Core.Compose
|
||||||
{
|
{
|
||||||
@@ -12,18 +13,18 @@ namespace Umbraco.Core.Compose
|
|||||||
private readonly IRuntimeState _runtimeState;
|
private readonly IRuntimeState _runtimeState;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IIOHelper _ioHelper;
|
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
|
// if configured and in debug mode, a ManifestWatcher watches App_Plugins folders for
|
||||||
// package.manifest chances and restarts the application on any change
|
// package.manifest chances and restarts the application on any change
|
||||||
private ManifestWatcher _mw;
|
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;
|
_runtimeState = runtimeState;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_ioHelper = ioHelper;
|
_ioHelper = ioHelper;
|
||||||
_hostingEnvironment = hostingEnvironment;
|
_umbracoApplicationLifetime = umbracoApplicationLifetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
@@ -36,7 +37,7 @@ namespace Umbraco.Core.Compose
|
|||||||
var appPlugins = _ioHelper.MapPath("~/App_Plugins/");
|
var appPlugins = _ioHelper.MapPath("~/App_Plugins/");
|
||||||
if (Directory.Exists(appPlugins) == false) return;
|
if (Directory.Exists(appPlugins) == false) return;
|
||||||
|
|
||||||
_mw = new ManifestWatcher(_logger, _hostingEnvironment);
|
_mw = new ManifestWatcher(_logger, _umbracoApplicationLifetime);
|
||||||
_mw.Start(Directory.GetDirectories(appPlugins));
|
_mw.Start(Directory.GetDirectories(appPlugins));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,11 +49,6 @@ namespace Umbraco.Web.Hosting
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string ToAbsolute(string virtualPath, string root) => VirtualPathUtility.ToAbsolute(virtualPath, root);
|
public string ToAbsolute(string virtualPath, string root) => VirtualPathUtility.ToAbsolute(virtualPath, root);
|
||||||
public void LazyRestartApplication()
|
|
||||||
{
|
|
||||||
HttpRuntime.UnloadAppDomain();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RegisterObject(IRegisteredObject registeredObject)
|
public void RegisterObject(IRegisteredObject registeredObject)
|
||||||
{
|
{
|
||||||
var wrapped = new RegisteredObjectWrapper(registeredObject);
|
var wrapped = new RegisteredObjectWrapper(registeredObject);
|
||||||
|
|||||||
Reference in New Issue
Block a user