From c1b9e0b89996d90dd2af1b0fbc0a02d9c55b9463 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Thu, 13 Apr 2023 17:56:03 +0300 Subject: [PATCH] Remove dependency on ICacheConfigurationSectionHandler from ConfigurationProvider.Current --- ...reDistributedCacheSectionHandlerFixture.cs | 2 +- .../CoreMemoryCacheSectionHandlerFixture.cs | 2 +- .../ConfigurationProviderBase.cs | 28 ++++++++++++------- .../RtMemoryCacheSectionHandlerFixture.cs | 2 +- .../RedisSectionHandlerFixture.cs | 2 +- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/CoreDistributedCacheSectionHandlerFixture.cs b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/CoreDistributedCacheSectionHandlerFixture.cs index 3506446..5987625 100644 --- a/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/CoreDistributedCacheSectionHandlerFixture.cs +++ b/CoreDistributedCache/NHibernate.Caches.CoreDistributedCache.Tests/CoreDistributedCacheSectionHandlerFixture.cs @@ -123,7 +123,7 @@ public void TestGetConfigFromProvidedConfiguration() Assert.That(fooRegion.Properties["expiration"], Is.EqualTo("500")); } - private ConfigurationProviderBase _configurationProviderBackup; + private ConfigurationProviderBase _configurationProviderBackup; [SetUp] public void OnSetup() diff --git a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache.Tests/CoreMemoryCacheSectionHandlerFixture.cs b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache.Tests/CoreMemoryCacheSectionHandlerFixture.cs index 0e1995a..6379599 100644 --- a/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache.Tests/CoreMemoryCacheSectionHandlerFixture.cs +++ b/CoreMemoryCache/NHibernate.Caches.CoreMemoryCache.Tests/CoreMemoryCacheSectionHandlerFixture.cs @@ -95,7 +95,7 @@ public void TestGetConfigFromProvidedConfiguration() Assert.That(config.Regions[0].Properties["expiration"], Is.EqualTo("500")); } - private ConfigurationProviderBase _configurationProviderBackup; + private ConfigurationProviderBase _configurationProviderBackup; [SetUp] public void OnSetup() diff --git a/NHibernate.Caches.Common/ConfigurationProviderBase.cs b/NHibernate.Caches.Common/ConfigurationProviderBase.cs index 9946157..97b6385 100644 --- a/NHibernate.Caches.Common/ConfigurationProviderBase.cs +++ b/NHibernate.Caches.Common/ConfigurationProviderBase.cs @@ -4,16 +4,30 @@ namespace NHibernate.Caches.Common { + /// + /// Base generic class for the cache configuration settings. + /// + /// The configuration class. + public abstract class ConfigurationProviderBase + where TConfig : class + { + /// + /// Get the cache configuration. + /// + /// The cache configuration. + public abstract TConfig GetConfiguration(); + } + /// /// Base generic class for the cache configuration settings. /// /// The configuration class. /// The configuration class section handler. - public abstract class ConfigurationProviderBase + public abstract class ConfigurationProviderBase : ConfigurationProviderBase where TConfig : class where TConfigHandler : ICacheConfigurationSectionHandler, new() { - private static ConfigurationProviderBase _current; + private static ConfigurationProviderBase _current; private static readonly string ConfigurationSectionName; static ConfigurationProviderBase() @@ -25,7 +39,7 @@ static ConfigurationProviderBase() /// Provides ability to override default with custom implementation. /// Can be set to null if all configuration is specified by code. /// - public static ConfigurationProviderBase Current + public static ConfigurationProviderBase Current { get => _current ?? (_current = new StaticConfigurationManagerProvider()); set => _current = value ?? new NullConfigurationProvider(); @@ -41,12 +55,6 @@ public static void SetConfiguration(Configuration configuration) _current = configuration == null ? null : new SystemConfigurationProvider(configuration); } - /// - /// Get the cache configuration. - /// - /// The cache configuration. - public abstract TConfig GetConfiguration(); - private class StaticConfigurationManagerProvider : ConfigurationProviderBase { /// @@ -83,7 +91,7 @@ public override TConfig GetConfiguration() } } - private class NullConfigurationProvider : ConfigurationProviderBase + private class NullConfigurationProvider : ConfigurationProviderBase { /// public override TConfig GetConfiguration() diff --git a/RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheSectionHandlerFixture.cs b/RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheSectionHandlerFixture.cs index 6e37036..c39a2fb 100644 --- a/RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheSectionHandlerFixture.cs +++ b/RtMemoryCache/NHibernate.Caches.RtMemoryCache.Tests/RtMemoryCacheSectionHandlerFixture.cs @@ -85,7 +85,7 @@ public void TestGetConfigFromProvidedConfiguration() Assert.That(config[0].Properties["expiration"], Is.EqualTo("500")); } - private ConfigurationProviderBase _configurationProviderBackup; + private ConfigurationProviderBase _configurationProviderBackup; [SetUp] public void OnSetup() diff --git a/StackExchangeRedis/NHibernate.Caches.StackExchangeRedis.Tests/RedisSectionHandlerFixture.cs b/StackExchangeRedis/NHibernate.Caches.StackExchangeRedis.Tests/RedisSectionHandlerFixture.cs index 99a29e6..b0b9dd4 100644 --- a/StackExchangeRedis/NHibernate.Caches.StackExchangeRedis.Tests/RedisSectionHandlerFixture.cs +++ b/StackExchangeRedis/NHibernate.Caches.StackExchangeRedis.Tests/RedisSectionHandlerFixture.cs @@ -92,7 +92,7 @@ public void TestGetConfigFromProvidedConfiguration() Assert.That(config.Regions[0].Expiration, Is.EqualTo(TimeSpan.FromSeconds(500))); } - private ConfigurationProviderBase _configurationProviderBackup; + private ConfigurationProviderBase _configurationProviderBackup; [SetUp] public void OnSetup()