diff --git a/src/Umbraco.Core/PublishedCache/DefaultCultureAccessor.cs b/src/Umbraco.Core/PublishedCache/DefaultCultureAccessor.cs index 50ec3c4c16..145206daf1 100644 --- a/src/Umbraco.Core/PublishedCache/DefaultCultureAccessor.cs +++ b/src/Umbraco.Core/PublishedCache/DefaultCultureAccessor.cs @@ -10,8 +10,9 @@ namespace Umbraco.Cms.Core.PublishedCache public class DefaultCultureAccessor : IDefaultCultureAccessor { private readonly ILocalizationService _localizationService; + private readonly IRuntimeState _runtimeState; private readonly IOptions _options; - private readonly RuntimeLevel _runtimeLevel; + /// /// Initializes a new instance of the class. @@ -19,12 +20,13 @@ namespace Umbraco.Cms.Core.PublishedCache public DefaultCultureAccessor(ILocalizationService localizationService, IRuntimeState runtimeState, IOptions options) { _localizationService = localizationService; + _runtimeState = runtimeState; _options = options; - _runtimeLevel = runtimeState.Level; + } /// - 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 } diff --git a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs index 956370a056..4bc7141fae 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs @@ -24,23 +24,25 @@ namespace Umbraco.Cms.Core.Services.Implement /// internal class UserService : RepositoryService, IUserService { + private readonly IRuntimeState _runtimeState; private readonly IUserRepository _userRepository; private readonly IUserGroupRepository _userGroupRepository; private readonly GlobalSettings _globalSettings; - private readonly bool _isUpgrading; private readonly ILogger _logger; public UserService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IRuntimeState runtimeState, IUserRepository userRepository, IUserGroupRepository userGroupRepository, IOptions globalSettings) : base(provider, loggerFactory, eventMessagesFactory) { + _runtimeState = runtimeState; _userRepository = userRepository; _userGroupRepository = userGroupRepository; _globalSettings = globalSettings.Value; - _isUpgrading = runtimeState.Level == RuntimeLevel.Install || runtimeState.Level == RuntimeLevel.Upgrade; _logger = loggerFactory.CreateLogger(); } + private bool IsUpgrading => _runtimeState.Level == RuntimeLevel.Install || _runtimeState.Level == RuntimeLevel.Upgrade; + #region Implementation of IMembershipUserService /// @@ -205,7 +207,7 @@ namespace Umbraco.Cms.Core.Services.Implement // currently kinda accepting anything on upgrade, but that won't deal with all cases // so we need to do it differently, see the custom UmbracoPocoDataBuilder which should // be better BUT requires that the app restarts after the upgrade! - if (_isUpgrading) + if (IsUpgrading) { //NOTE: this will not be cached return _userRepository.GetByUsername(username, includeSecurityData: false); @@ -305,7 +307,7 @@ namespace Umbraco.Cms.Core.Services.Implement catch (DbException ex) { // if we are upgrading and an exception occurs, log and swallow it - if (_isUpgrading == false) throw; + if (IsUpgrading == false) throw; _logger.LogWarning(ex, "An error occurred attempting to save a user instance during upgrade, normally this warning can be ignored"); @@ -681,7 +683,7 @@ namespace Umbraco.Cms.Core.Services.Implement // currently kinda accepting anything on upgrade, but that won't deal with all cases // so we need to do it differently, see the custom UmbracoPocoDataBuilder which should // be better BUT requires that the app restarts after the upgrade! - if (_isUpgrading) + if (IsUpgrading) { //NOTE: this will not be cached return _userRepository.Get(id, includeSecurityData: false);