123456789101112131415161718192021222324252627282930313233343536 |
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.DependencyInjection.Extensions;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using TEAMModelOS.SDK.DI;
- namespace TEAMModelOS.SDK.DI.Multiple
- {
- public static class MultipleAzureRedisFactoryExtensions
- {
- /// <summary>
- /// Redis数据库注入
- /// </summary>
- /// <param name="services"></param>
- /// <param name="connectionInfos"></param>
- /// <returns></returns>
- /// <exception cref="ArgumentNullException"></exception>
- public static IServiceCollection AddMultipleAzureRedis(this IServiceCollection services, List<(string name, string connectionString)> connectionInfos)
- {
- if (services == null) throw new ArgumentNullException(nameof(services));
- if (connectionInfos == null) throw new ArgumentNullException(nameof(connectionInfos));
- services.TryAddSingleton<AzureRedisFactory>();
- //多个连接字符串注入
- connectionInfos.ForEach(connection =>
- {
- services.Configure<AzureRedisFactoryOptions>(connection.name, o => { o.Name = connection.name; o.RedisConnectionString = connection.connectionString; });
- });
- ////单个连接字符注入
- //services.Configure<AzureRedisFactoryOptions>(name, o => { o.Name = name; o.RedisConnectionString = connectionString; });
- return services;
- }
- }
- }
|