From 16ff840a8e4c8acb1c0d55c6ff52913d5c9a40f8 Mon Sep 17 00:00:00 2001 From: Martin Kyjac Date: Thu, 1 Aug 2024 09:54:16 +0200 Subject: [PATCH] Use option monitor's current value in constructor --- .../ShopifyIntegrationSettingsService.cs | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/Kentico.Xperience.Shopify/Config/ShopifyIntegrationSettingsService.cs b/src/Kentico.Xperience.Shopify/Config/ShopifyIntegrationSettingsService.cs index 52e0138..c80ad6e 100644 --- a/src/Kentico.Xperience.Shopify/Config/ShopifyIntegrationSettingsService.cs +++ b/src/Kentico.Xperience.Shopify/Config/ShopifyIntegrationSettingsService.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; - -using CMS.DataEngine; +using CMS.DataEngine; using CMS.Helpers; using CMS.Websites.Routing; @@ -13,9 +11,9 @@ namespace Kentico.Xperience.Shopify.Config internal class ShopifyIntegrationSettingsService : IShopifyIntegrationSettingsService { private readonly IProgressiveCache cache; - private readonly IOptionsMonitor shopifyConfigMonitor; + private readonly ShopifyConfig shopifyConfig; private readonly IInfoProvider integrationSettingsProvider; - private readonly IOptionsMonitor websiteChannelConfigMonitor; + private readonly ShopifyWebsiteChannelConfigOptions websiteChannelConfig; private readonly IWebsiteChannelContext websiteChannelContext; public ShopifyIntegrationSettingsService( @@ -26,19 +24,17 @@ public ShopifyIntegrationSettingsService( IWebsiteChannelContext websiteChannelContext) { this.cache = cache; - this.shopifyConfigMonitor = shopifyConfigMonitor; this.integrationSettingsProvider = integrationSettingsProvider; - this.websiteChannelConfigMonitor = websiteChannelConfigMonitor; this.websiteChannelContext = websiteChannelContext; + shopifyConfig = shopifyConfigMonitor.CurrentValue; + websiteChannelConfig = websiteChannelConfigMonitor.CurrentValue; } public ShopifyConfig? GetSettings() { - var monitorValue = shopifyConfigMonitor.CurrentValue; - - if (ShopifyConfigIsFilled(monitorValue)) + if (ShopifyConfigIsFilled(shopifyConfig)) { - return monitorValue; + return shopifyConfig; } return cache.Load(cs => GetConfigFromSettings(), @@ -51,9 +47,7 @@ public ShopifyIntegrationSettingsService( public ShopifyWebsiteChannelConfig? GetWebsiteChannelSettings() { - var monitorValue = websiteChannelConfigMonitor.CurrentValue; - - if (monitorValue == null) + if (websiteChannelConfig == null) { return null; } @@ -61,9 +55,9 @@ public ShopifyIntegrationSettingsService( string? currentChannel = websiteChannelContext.WebsiteChannelName; if (string.IsNullOrEmpty(currentChannel)) { - return monitorValue.DefaultSetting; + return websiteChannelConfig.DefaultSetting; } - return monitorValue.Settings?.Find(x => x.ChannelName == currentChannel) ?? monitorValue.DefaultSetting; + return websiteChannelConfig.Settings?.Find(x => x.ChannelName == currentChannel) ?? websiteChannelConfig.DefaultSetting; } private ShopifyConfig? GetConfigFromSettings()