Removed static ApplicationUrlHelper and introduced IBackOfficeInfo and AspNetBackOfficeInfo
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Web;
|
|
||||||
using Semver;
|
using Semver;
|
||||||
using Umbraco.Core.Configuration;
|
using Umbraco.Core.Configuration;
|
||||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||||
@@ -28,13 +27,15 @@ namespace Umbraco.Core
|
|||||||
private readonly Lazy<IServerRegistrar> _serverRegistrar;
|
private readonly Lazy<IServerRegistrar> _serverRegistrar;
|
||||||
private readonly IUmbracoVersion _umbracoVersion;
|
private readonly IUmbracoVersion _umbracoVersion;
|
||||||
private readonly IHostingEnvironment _hostingEnvironment;
|
private readonly IHostingEnvironment _hostingEnvironment;
|
||||||
|
private readonly IBackOfficeInfo _backOfficeInfo;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RuntimeState"/> class.
|
/// Initializes a new instance of the <see cref="RuntimeState"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RuntimeState(ILogger logger, IUmbracoSettingsSection settings, IGlobalSettings globalSettings,
|
public RuntimeState(ILogger logger, IUmbracoSettingsSection settings, IGlobalSettings globalSettings,
|
||||||
Lazy<IMainDom> mainDom, Lazy<IServerRegistrar> serverRegistrar, IUmbracoVersion umbracoVersion,
|
Lazy<IMainDom> mainDom, Lazy<IServerRegistrar> serverRegistrar, IUmbracoVersion umbracoVersion,
|
||||||
IHostingEnvironment hostingEnvironment)
|
IHostingEnvironment hostingEnvironment,
|
||||||
|
IBackOfficeInfo backOfficeInfo)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
@@ -43,6 +44,7 @@ namespace Umbraco.Core
|
|||||||
_serverRegistrar = serverRegistrar;
|
_serverRegistrar = serverRegistrar;
|
||||||
_umbracoVersion = umbracoVersion;
|
_umbracoVersion = umbracoVersion;
|
||||||
_hostingEnvironment = hostingEnvironment;
|
_hostingEnvironment = hostingEnvironment;
|
||||||
|
_backOfficeInfo = backOfficeInfo;
|
||||||
|
|
||||||
ApplicationVirtualPath = _hostingEnvironment.ApplicationVirtualPath;
|
ApplicationVirtualPath = _hostingEnvironment.ApplicationVirtualPath;
|
||||||
}
|
}
|
||||||
@@ -99,31 +101,45 @@ namespace Umbraco.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public RuntimeLevelReason Reason { get; internal set; } = RuntimeLevelReason.Unknown;
|
public RuntimeLevelReason Reason { get; internal set; } = RuntimeLevelReason.Unknown;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ensures that the <see cref="ApplicationUrl"/> property has a value.
|
internal void EnsureApplicationUrl()
|
||||||
/// </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
|
var url = _backOfficeInfo.GetAbsoluteUrl;
|
||||||
// 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);
|
var change = url != null && !_applicationUrls.Contains(url);
|
||||||
|
|
||||||
if (change)
|
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);
|
_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 />
|
/// <inheritdoc />
|
||||||
public BootFailedException BootFailedException { get; internal set; }
|
public BootFailedException BootFailedException { get; internal set; }
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace Umbraco.Tests.Routing
|
|||||||
var logger = Mock.Of<ILogger>();
|
var logger = Mock.Of<ILogger>();
|
||||||
var globalSettings = TestObjects.GetGlobalSettings();
|
var globalSettings = TestObjects.GetGlobalSettings();
|
||||||
var runtime = new RuntimeState(logger, Mock.Of<IUmbracoSettingsSection>(), globalSettings,
|
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
|
_module = new UmbracoInjectedModule
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ namespace Umbraco.Tests.Testing
|
|||||||
protected virtual IProfilingLogger ProfilingLogger => Factory.GetInstance<IProfilingLogger>();
|
protected virtual IProfilingLogger ProfilingLogger => Factory.GetInstance<IProfilingLogger>();
|
||||||
|
|
||||||
protected IHostingEnvironment HostingEnvironment => Factory.GetInstance<IHostingEnvironment>();
|
protected IHostingEnvironment HostingEnvironment => Factory.GetInstance<IHostingEnvironment>();
|
||||||
|
protected IBackOfficeInfo BackOfficeInfo => Factory.GetInstance<IBackOfficeInfo>();
|
||||||
protected AppCaches AppCaches => Factory.GetInstance<AppCaches>();
|
protected AppCaches AppCaches => Factory.GetInstance<AppCaches>();
|
||||||
|
|
||||||
protected virtual ISqlSyntaxProvider SqlSyntax => Factory.GetInstance<ISqlSyntaxProvider>();
|
protected virtual ISqlSyntaxProvider SqlSyntax => Factory.GetInstance<ISqlSyntaxProvider>();
|
||||||
@@ -143,7 +144,9 @@ namespace Umbraco.Tests.Testing
|
|||||||
TypeFinder = new TypeFinder(logger);
|
TypeFinder = new TypeFinder(logger);
|
||||||
var appCaches = GetAppCaches();
|
var appCaches = GetAppCaches();
|
||||||
var globalSettings = SettingsForTests.GetDefaultGlobalSettings();
|
var globalSettings = SettingsForTests.GetDefaultGlobalSettings();
|
||||||
|
var settings = SettingsForTests.GetDefaultUmbracoSettings();
|
||||||
IHostingEnvironment hostingEnvironment = new AspNetHostingEnvironment(globalSettings, IOHelper);
|
IHostingEnvironment hostingEnvironment = new AspNetHostingEnvironment(globalSettings, IOHelper);
|
||||||
|
IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, settings, logger);
|
||||||
UmbracoVersion = new UmbracoVersion(globalSettings);
|
UmbracoVersion = new UmbracoVersion(globalSettings);
|
||||||
var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, hostingEnvironment, proflogger, Options.TypeLoader);
|
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<IProfilingLogger>(proflogger);
|
||||||
Composition.RegisterUnique(appCaches);
|
Composition.RegisterUnique(appCaches);
|
||||||
Composition.RegisterUnique(hostingEnvironment);
|
Composition.RegisterUnique(hostingEnvironment);
|
||||||
|
Composition.RegisterUnique(backOfficeInfo);
|
||||||
|
|
||||||
TestObjects = new TestObjects(register);
|
TestObjects = new TestObjects(register);
|
||||||
Compose();
|
Compose();
|
||||||
|
|||||||
Reference in New Issue
Block a user