From cefed265639b28527a03df22b9cff7e164b1da6c Mon Sep 17 00:00:00 2001 From: Zeegaan <70372949+Zeegaan@users.noreply.github.com> Date: Thu, 23 Sep 2021 08:33:16 +0200 Subject: [PATCH] Use IOptionsSnapshot in transient services --- .../Handlers/AuditNotificationsHandler.cs | 7 +++---- .../AutoModelsNotificationHandler.cs | 4 ++-- .../Controllers/AuthenticationController.cs | 18 +++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Core/Handlers/AuditNotificationsHandler.cs b/src/Umbraco.Core/Handlers/AuditNotificationsHandler.cs index b3d30f7024..47a08c773a 100644 --- a/src/Umbraco.Core/Handlers/AuditNotificationsHandler.cs +++ b/src/Umbraco.Core/Handlers/AuditNotificationsHandler.cs @@ -30,7 +30,7 @@ namespace Umbraco.Cms.Core.Handlers private readonly IEntityService _entityService; private readonly IIpResolver _ipResolver; private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; - private GlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IMemberService _memberService; public AuditNotificationsHandler( @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Handlers IUserService userService, IEntityService entityService, IIpResolver ipResolver, - IOptionsMonitor globalSettings, + IOptionsSnapshot globalSettings, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, IMemberService memberService) { @@ -48,8 +48,7 @@ namespace Umbraco.Cms.Core.Handlers _ipResolver = ipResolver; _backOfficeSecurityAccessor = backOfficeSecurityAccessor; _memberService = memberService; - _globalSettings = globalSettings.CurrentValue; - globalSettings.OnChange(x => _globalSettings = x); + _globalSettings = globalSettings.Value; } private IUser CurrentPerformingUser diff --git a/src/Umbraco.Infrastructure/ModelsBuilder/AutoModelsNotificationHandler.cs b/src/Umbraco.Infrastructure/ModelsBuilder/AutoModelsNotificationHandler.cs index 8017cfbf8e..cb52b049ad 100644 --- a/src/Umbraco.Infrastructure/ModelsBuilder/AutoModelsNotificationHandler.cs +++ b/src/Umbraco.Infrastructure/ModelsBuilder/AutoModelsNotificationHandler.cs @@ -25,7 +25,7 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder { private static int s_req; private readonly ILogger _logger; - private readonly ModelsBuilderSettings _config; + private ModelsBuilderSettings _config; private readonly ModelsGenerator _modelGenerator; private readonly ModelsGenerationError _mbErrors; private readonly IMainDom _mainDom; @@ -35,7 +35,7 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder /// public AutoModelsNotificationHandler( ILogger logger, - IOptions config, + IOptionsSnapshot config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IMainDom mainDom) diff --git a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs index baa1ca0e09..cc8ff205b7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs @@ -60,11 +60,11 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers private readonly IUserService _userService; private readonly ILocalizedTextService _textService; private readonly IUmbracoMapper _umbracoMapper; - private GlobalSettings _globalSettings; - private SecuritySettings _securitySettings; + private readonly GlobalSettings _globalSettings; + private readonly SecuritySettings _securitySettings; private readonly ILogger _logger; private readonly IIpResolver _ipResolver; - private UserPasswordConfigurationSettings _passwordConfiguration; + private readonly UserPasswordConfigurationSettings _passwordConfiguration; private readonly IEmailSender _emailSender; private readonly ISmsSender _smsSender; private readonly IHostingEnvironment _hostingEnvironment; @@ -81,11 +81,11 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers IUserService userService, ILocalizedTextService textService, IUmbracoMapper umbracoMapper, - IOptionsMonitor globalSettings, - IOptionsMonitor securitySettings, + IOptionsSnapshot globalSettings, + IOptionsSnapshot securitySettings, ILogger logger, IIpResolver ipResolver, - IOptionsMonitor passwordConfiguration, + IOptionsSnapshot passwordConfiguration, IEmailSender emailSender, ISmsSender smsSender, IHostingEnvironment hostingEnvironment, @@ -99,11 +99,11 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers _userService = userService; _textService = textService; _umbracoMapper = umbracoMapper; - _globalSettings = globalSettings.CurrentValue; - _securitySettings = securitySettings.CurrentValue; + _globalSettings = globalSettings.Value; + _securitySettings = securitySettings.Value; _logger = logger; _ipResolver = ipResolver; - _passwordConfiguration = passwordConfiguration.CurrentValue; + _passwordConfiguration = passwordConfiguration.Value; _emailSender = emailSender; _smsSender = smsSender; _hostingEnvironment = hostingEnvironment;