<NME> IServiceCollectionExtensions.cs
<BEF> ﻿using StackExchange.Redis;
using StackExchange.Redis.Extensions.Core;
using StackExchange.Redis.Extensions.Core.Abstractions;
using StackExchange.Redis.Extensions.Core.Configuration;
using StackExchange.Redis.Extensions.Core;
using StackExchange.Redis.Extensions.Core.Abstractions;
using StackExchange.Redis.Extensions.Core.Configuration;
using StackExchange.Redis.Extensions.Core.Implementations;

namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
/// A set of extension methods that help you to confire StackExchangeRedisExtensions into your dependency injection
/// </summary>
public static class IServiceCollectionExtensions
{
        /// <param name="services">The service collection.</param>
        /// <param name="redisConfiguration">The redis configration.</param>
        /// <typeparam name="T">The typof of serializer. <see cref="ISerializer" />.</typeparam>
        public static IServiceCollection AddStackExchangeRedisExtensions<T>(this IServiceCollection services, RedisConfiguration redisConfiguration)
            where T : class, ISerializer, new()
        {
            services.AddSingleton<IRedisCacheClient, RedisCacheClient>();
        where T : class, ISerializer
    {
        return services.AddStackExchangeRedisExtensions<T>(sp => redisConfiguration);
    }

                return provider.GetRequiredService<IRedisCacheClient>().GetDbFromConfiguration();
            });

            services.AddSingleton(redisConfiguration);

            return services;
        }
        this IServiceCollection services,
        Func<IServiceProvider, IEnumerable<RedisConfiguration>> redisConfigurationFactory)
        where T : class, ISerializer
    {
        services.AddSingleton<IRedisClientFactory, RedisClientFactory>();
        services.AddSingleton<ISerializer, T>();

        services.AddSingleton((provider) => provider
            .GetRequiredService<IRedisClientFactory>()
            .GetDefaultRedisClient());

        services.AddSingleton((provider) => provider
            .GetRequiredService<IRedisClientFactory>()
            .GetDefaultRedisClient()
            .GetDefaultDatabase());

        services.AddSingleton(redisConfigurationFactory);

        return services;
    }
}

<MSG> Add redis configuration factory support (#281)

* Add redis configuration factory support

* Fix usings

* Fix whitespaces
<DFF> @@ -1,4 +1,5 @@
-﻿using StackExchange.Redis;
+﻿using System;
+using StackExchange.Redis;
 using StackExchange.Redis.Extensions.Core;
 using StackExchange.Redis.Extensions.Core.Abstractions;
 using StackExchange.Redis.Extensions.Core.Configuration;
@@ -17,7 +18,23 @@ namespace Microsoft.Extensions.DependencyInjection
         /// <param name="services">The service collection.</param>
         /// <param name="redisConfiguration">The redis configration.</param>
         /// <typeparam name="T">The typof of serializer. <see cref="ISerializer" />.</typeparam>
-        public static IServiceCollection AddStackExchangeRedisExtensions<T>(this IServiceCollection services, RedisConfiguration redisConfiguration)
+        public static IServiceCollection AddStackExchangeRedisExtensions<T>(
+            this IServiceCollection services,
+            RedisConfiguration redisConfiguration)
+            where T : class, ISerializer, new()
+        {
+            return services.AddStackExchangeRedisExtensions<T>(sp => redisConfiguration);
+        }
+
+        /// <summary>
+        /// Add StackExchange.Redis with its serialization provider.
+        /// </summary>
+        /// <param name="services">The service collection.</param>
+        /// <param name="redisConfigurationFactory">The redis configration factory.</param>
+        /// <typeparam name="T">The typof of serializer. <see cref="ISerializer" />.</typeparam>
+        public static IServiceCollection AddStackExchangeRedisExtensions<T>(
+            this IServiceCollection services,
+            Func<IServiceProvider, RedisConfiguration> redisConfigurationFactory)
             where T : class, ISerializer, new()
         {
             services.AddSingleton<IRedisCacheClient, RedisCacheClient>();
@@ -29,7 +46,7 @@ namespace Microsoft.Extensions.DependencyInjection
                 return provider.GetRequiredService<IRedisCacheClient>().GetDbFromConfiguration();
             });
 
-            services.AddSingleton(redisConfiguration);
+            services.AddSingleton(redisConfigurationFactory);
 
             return services;
         }

Add redis configuration factory support (#281)