Removed static ApplicationUrlHelper and introduced IBackOfficeInfo and AspNetBackOfficeInfo
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using Semver;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
@@ -28,13 +27,15 @@ namespace Umbraco.Core
|
||||
private readonly Lazy<IServerRegistrar> _serverRegistrar;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IBackOfficeInfo _backOfficeInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RuntimeState"/> class.
|
||||
/// </summary>
|
||||
public RuntimeState(ILogger logger, IUmbracoSettingsSection settings, IGlobalSettings globalSettings,
|
||||
Lazy<IMainDom> mainDom, Lazy<IServerRegistrar> serverRegistrar, IUmbracoVersion umbracoVersion,
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IBackOfficeInfo backOfficeInfo)
|
||||
{
|
||||
_logger = logger;
|
||||
_settings = settings;
|
||||
@@ -43,6 +44,7 @@ namespace Umbraco.Core
|
||||
_serverRegistrar = serverRegistrar;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_backOfficeInfo = backOfficeInfo;
|
||||
|
||||
ApplicationVirtualPath = _hostingEnvironment.ApplicationVirtualPath;
|
||||
}
|
||||
@@ -99,31 +101,45 @@ namespace Umbraco.Core
|
||||
/// <inheritdoc />
|
||||
public RuntimeLevelReason Reason { get; internal set; } = RuntimeLevelReason.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the <see cref="ApplicationUrl"/> property has a value.
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
internal void EnsureApplicationUrl(HttpRequestBase request = null)
|
||||
|
||||
internal void EnsureApplicationUrl()
|
||||
{
|
||||
//Fixme: This causes problems with site swap on azure because azure pre-warms a site by calling into `localhost` and when it does that
|
||||
// it changes the URL to `localhost:80` which actually doesn't work for pinging itself, it only works internally in Azure. The ironic part
|
||||
// about this is that this is here specifically for the slot swap scenario https://issues.umbraco.org/issue/U4-10626
|
||||
var url = _backOfficeInfo.GetAbsoluteUrl;
|
||||
|
||||
|
||||
// see U4-10626 - in some cases we want to reset the application url
|
||||
// (this is a simplified version of what was in 7.x)
|
||||
// note: should this be optional? is it expensive?
|
||||
var url = request == null ? null : ApplicationUrlHelper.GetApplicationUrlFromCurrentRequest(request, _globalSettings);
|
||||
var change = url != null && !_applicationUrls.Contains(url);
|
||||
|
||||
if (change)
|
||||
{
|
||||
_logger.Info(typeof(ApplicationUrlHelper), "New url {Url} detected, re-discovering application url.", url);
|
||||
_logger.Info<RuntimeState>("New url {Url} detected, re-discovering application url.", url);
|
||||
_applicationUrls.Add(url);
|
||||
ApplicationUrl = new Uri(url);
|
||||
}
|
||||
|
||||
if (ApplicationUrl != null && !change) return;
|
||||
ApplicationUrl = new Uri(ApplicationUrlHelper.GetApplicationUrl(_logger, _globalSettings, _settings, ServerRegistrar, request));
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Ensures that the <see cref="ApplicationUrl"/> property has a value.
|
||||
// /// </summary>
|
||||
// /// <param name="request"></param>
|
||||
// internal void EnsureApplicationUrl(HttpRequestBase request = null)
|
||||
// {
|
||||
// //Fixme: This causes problems with site swap on azure because azure pre-warms a site by calling into `localhost` and when it does that
|
||||
// // it changes the URL to `localhost:80` which actually doesn't work for pinging itself, it only works internally in Azure. The ironic part
|
||||
// // about this is that this is here specifically for the slot swap scenario https://issues.umbraco.org/issue/U4-10626
|
||||
//
|
||||
//
|
||||
// // see U4-10626 - in some cases we want to reset the application url
|
||||
// // (this is a simplified version of what was in 7.x)
|
||||
// // note: should this be optional? is it expensive?
|
||||
// var url = request == null ? null : ApplicationUrlHelper.GetApplicationUrlFromCurrentRequest(request, _globalSettings);
|
||||
// var change = url != null && !_applicationUrls.Contains(url);
|
||||
// if (change)
|
||||
// {
|
||||
// _logger.Info(typeof(ApplicationUrlHelper), "New url {Url} detected, re-discovering application url.", url);
|
||||
// _applicationUrls.Add(url);
|
||||
// }
|
||||
//
|
||||
// if (ApplicationUrl != null && !change) return;
|
||||
// ApplicationUrl = new Uri(ApplicationUrlHelper.GetApplicationUrl(_logger, _globalSettings, _settings, ServerRegistrar, request));
|
||||
// }
|
||||
|
||||
/// <inheritdoc />
|
||||
public BootFailedException BootFailedException { get; internal set; }
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Tests.Routing
|
||||
var logger = Mock.Of<ILogger>();
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var runtime = new RuntimeState(logger, Mock.Of<IUmbracoSettingsSection>(), globalSettings,
|
||||
new Lazy<IMainDom>(), new Lazy<IServerRegistrar>(), UmbracoVersion, HostingEnvironment);
|
||||
new Lazy<IMainDom>(), new Lazy<IServerRegistrar>(), UmbracoVersion, HostingEnvironment, BackOfficeInfo);
|
||||
|
||||
_module = new UmbracoInjectedModule
|
||||
(
|
||||
|
||||
@@ -111,6 +111,7 @@ namespace Umbraco.Tests.Testing
|
||||
protected virtual IProfilingLogger ProfilingLogger => Factory.GetInstance<IProfilingLogger>();
|
||||
|
||||
protected IHostingEnvironment HostingEnvironment => Factory.GetInstance<IHostingEnvironment>();
|
||||
protected IBackOfficeInfo BackOfficeInfo => Factory.GetInstance<IBackOfficeInfo>();
|
||||
protected AppCaches AppCaches => Factory.GetInstance<AppCaches>();
|
||||
|
||||
protected virtual ISqlSyntaxProvider SqlSyntax => Factory.GetInstance<ISqlSyntaxProvider>();
|
||||
@@ -143,7 +144,9 @@ namespace Umbraco.Tests.Testing
|
||||
TypeFinder = new TypeFinder(logger);
|
||||
var appCaches = GetAppCaches();
|
||||
var globalSettings = SettingsForTests.GetDefaultGlobalSettings();
|
||||
var settings = SettingsForTests.GetDefaultUmbracoSettings();
|
||||
IHostingEnvironment hostingEnvironment = new AspNetHostingEnvironment(globalSettings, IOHelper);
|
||||
IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, settings, logger);
|
||||
UmbracoVersion = new UmbracoVersion(globalSettings);
|
||||
var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, hostingEnvironment, proflogger, Options.TypeLoader);
|
||||
|
||||
@@ -161,6 +164,7 @@ namespace Umbraco.Tests.Testing
|
||||
Composition.RegisterUnique<IProfilingLogger>(proflogger);
|
||||
Composition.RegisterUnique(appCaches);
|
||||
Composition.RegisterUnique(hostingEnvironment);
|
||||
Composition.RegisterUnique(backOfficeInfo);
|
||||
|
||||
TestObjects = new TestObjects(register);
|
||||
Compose();
|
||||
|
||||
Reference in New Issue
Block a user