Fixed issues where RuntimeState.Level was used in ctors. This is not a good idea, as these ctors are executed before the level are determined.

This commit is contained in:
Bjarke Berg
2021-05-07 07:40:08 +02:00
parent cb01e11586
commit 145a0fabe7
2 changed files with 12 additions and 8 deletions

View File

@@ -10,8 +10,9 @@ namespace Umbraco.Cms.Core.PublishedCache
public class DefaultCultureAccessor : IDefaultCultureAccessor
{
private readonly ILocalizationService _localizationService;
private readonly IRuntimeState _runtimeState;
private readonly IOptions<GlobalSettings> _options;
private readonly RuntimeLevel _runtimeLevel;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultCultureAccessor"/> class.
@@ -19,12 +20,13 @@ namespace Umbraco.Cms.Core.PublishedCache
public DefaultCultureAccessor(ILocalizationService localizationService, IRuntimeState runtimeState, IOptions<GlobalSettings> options)
{
_localizationService = localizationService;
_runtimeState = runtimeState;
_options = options;
_runtimeLevel = runtimeState.Level;
}
/// <inheritdoc />
public string DefaultCulture => _runtimeLevel == RuntimeLevel.Run
public string DefaultCulture => _runtimeState.Level == RuntimeLevel.Run
? _localizationService.GetDefaultLanguageIsoCode() ?? "" // fast
: _options.Value.DefaultUILanguage; // default for install and upgrade, when the service is n/a
}