Skip to content

Commit

Permalink
Use option monitor's current value in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkyjac committed Aug 1, 2024
1 parent 602c161 commit 16ff840
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics;

using CMS.DataEngine;
using CMS.DataEngine;
using CMS.Helpers;
using CMS.Websites.Routing;

Expand All @@ -13,9 +11,9 @@ namespace Kentico.Xperience.Shopify.Config
internal class ShopifyIntegrationSettingsService : IShopifyIntegrationSettingsService
{
private readonly IProgressiveCache cache;
private readonly IOptionsMonitor<ShopifyConfig> shopifyConfigMonitor;
private readonly ShopifyConfig shopifyConfig;
private readonly IInfoProvider<IntegrationSettingsInfo> integrationSettingsProvider;
private readonly IOptionsMonitor<ShopifyWebsiteChannelConfigOptions> websiteChannelConfigMonitor;
private readonly ShopifyWebsiteChannelConfigOptions websiteChannelConfig;
private readonly IWebsiteChannelContext websiteChannelContext;

public ShopifyIntegrationSettingsService(
Expand All @@ -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(),
Expand All @@ -51,19 +47,17 @@ public ShopifyIntegrationSettingsService(

public ShopifyWebsiteChannelConfig? GetWebsiteChannelSettings()
{
var monitorValue = websiteChannelConfigMonitor.CurrentValue;

if (monitorValue == null)
if (websiteChannelConfig == null)
{
return null;
}

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()
Expand Down

0 comments on commit 16ff840

Please sign in to comment.