Fix UmbracoContext issue (with a TODO)

This commit is contained in:
Stephan
2019-02-15 10:31:45 +01:00
parent 2adec8ee74
commit a46d40e9ef
2 changed files with 9 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using Umbraco.Core.Services;
using Umbraco.Core;
using Umbraco.Core.Services;
namespace Umbraco.Web.PublishedCache
{
@@ -8,17 +9,20 @@ namespace Umbraco.Web.PublishedCache
public class DefaultCultureAccessor : IDefaultCultureAccessor
{
private readonly ILocalizationService _localizationService;
private readonly RuntimeLevel _runtimeLevel;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultCultureAccessor"/> class.
/// </summary>
/// <param name="localizationService"></param>
public DefaultCultureAccessor(ILocalizationService localizationService)
public DefaultCultureAccessor(ILocalizationService localizationService, IRuntimeState runtimeState)
{
_localizationService = localizationService;
_runtimeLevel = runtimeState.Level;
}
/// <inheritdoc />
public string DefaultCulture => _localizationService.GetDefaultLanguageIsoCode() ?? ""; // fast
public string DefaultCulture => _runtimeLevel == RuntimeLevel.Run
? _localizationService.GetDefaultLanguageIsoCode() ?? "" // fast
: "en-US"; // default for install and upgrade, when the service is n/a
}
}

View File

@@ -95,6 +95,7 @@ namespace Umbraco.Web
// ok, process
// TODO: should we move this to after we've ensured we are processing a routable page?
// ensure there's an UmbracoContext registered for the current request
// registers the context reference so its disposed at end of request
var umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext(httpContext);