Skip to content

Commit

Permalink
Remove dependency on ICacheConfigurationSectionHandler from Configura…
Browse files Browse the repository at this point in the history
…tionProvider.Current
  • Loading branch information
bahusoid committed Apr 13, 2023
1 parent 196296f commit c1b9e0b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void TestGetConfigFromProvidedConfiguration()
Assert.That(fooRegion.Properties["expiration"], Is.EqualTo("500"));
}

private ConfigurationProviderBase<CacheConfig, CoreDistributedCacheSectionHandler> _configurationProviderBackup;
private ConfigurationProviderBase<CacheConfig> _configurationProviderBackup;

[SetUp]
public void OnSetup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void TestGetConfigFromProvidedConfiguration()
Assert.That(config.Regions[0].Properties["expiration"], Is.EqualTo("500"));
}

private ConfigurationProviderBase<CacheConfig, CoreMemoryCacheSectionHandler> _configurationProviderBackup;
private ConfigurationProviderBase<CacheConfig> _configurationProviderBackup;

[SetUp]
public void OnSetup()
Expand Down
28 changes: 18 additions & 10 deletions NHibernate.Caches.Common/ConfigurationProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@

namespace NHibernate.Caches.Common
{
/// <summary>
/// Base generic class for the cache configuration settings.
/// </summary>
/// <typeparam name="TConfig">The configuration class.</typeparam>
public abstract class ConfigurationProviderBase<TConfig>
where TConfig : class
{
/// <summary>
/// Get the cache configuration.
/// </summary>
/// <returns>The cache configuration.</returns>
public abstract TConfig GetConfiguration();
}

/// <summary>
/// Base generic class for the cache configuration settings.
/// </summary>
/// <typeparam name="TConfig">The configuration class.</typeparam>
/// <typeparam name="TConfigHandler">The configuration class section handler.</typeparam>
public abstract class ConfigurationProviderBase<TConfig, TConfigHandler>
public abstract class ConfigurationProviderBase<TConfig, TConfigHandler> : ConfigurationProviderBase<TConfig>
where TConfig : class
where TConfigHandler : ICacheConfigurationSectionHandler, new()
{
private static ConfigurationProviderBase<TConfig, TConfigHandler> _current;
private static ConfigurationProviderBase<TConfig> _current;
private static readonly string ConfigurationSectionName;

static ConfigurationProviderBase()
Expand All @@ -25,7 +39,7 @@ static ConfigurationProviderBase()
/// Provides ability to override default <see cref="System.Configuration.ConfigurationManager"/> with custom implementation.
/// Can be set to null if all configuration is specified by code.
/// </summary>
public static ConfigurationProviderBase<TConfig, TConfigHandler> Current
public static ConfigurationProviderBase<TConfig> Current
{
get => _current ?? (_current = new StaticConfigurationManagerProvider());
set => _current = value ?? new NullConfigurationProvider();
Expand All @@ -41,12 +55,6 @@ public static void SetConfiguration(Configuration configuration)
_current = configuration == null ? null : new SystemConfigurationProvider(configuration);
}

/// <summary>
/// Get the cache configuration.
/// </summary>
/// <returns>The cache configuration.</returns>
public abstract TConfig GetConfiguration();

private class StaticConfigurationManagerProvider : ConfigurationProviderBase<TConfig, TConfigHandler>
{
/// <inheritdoc />
Expand Down Expand Up @@ -83,7 +91,7 @@ public override TConfig GetConfiguration()
}
}

private class NullConfigurationProvider : ConfigurationProviderBase<TConfig, TConfigHandler>
private class NullConfigurationProvider : ConfigurationProviderBase<TConfig>
{
/// <inheritdoc />
public override TConfig GetConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void TestGetConfigFromProvidedConfiguration()
Assert.That(config[0].Properties["expiration"], Is.EqualTo("500"));
}

private ConfigurationProviderBase<CacheConfig[], RtMemoryCacheSectionHandler> _configurationProviderBackup;
private ConfigurationProviderBase<CacheConfig[]> _configurationProviderBackup;

[SetUp]
public void OnSetup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void TestGetConfigFromProvidedConfiguration()
Assert.That(config.Regions[0].Expiration, Is.EqualTo(TimeSpan.FromSeconds(500)));
}

private ConfigurationProviderBase<CacheConfig, RedisSectionHandler> _configurationProviderBackup;
private ConfigurationProviderBase<CacheConfig> _configurationProviderBackup;

[SetUp]
public void OnSetup()
Expand Down

0 comments on commit c1b9e0b

Please sign in to comment.