private static void DoAddIDistributedCache(IServiceCollection services, RedisServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime) { Type interfaceType = RedisTypeLocator.MicrosoftInterface; Type connectionType = RedisTypeLocator.MicrosoftImplementation; Type optionsType = RedisTypeLocator.MicrosoftOptions; RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config); RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig, connectionType, optionsType, null); services.Add(new ServiceDescriptor(interfaceType, factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(connectionType, factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RedisHealthContributor(factory, connectionType, ctx.GetService <ILogger <RedisHealthContributor> >()), ServiceLifetime.Singleton)); }
private static void DoAddConnectionMultiplexer(IServiceCollection services, RedisServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime) { Type redisInterface = RedisTypeLocator.StackExchangeInterface; Type redisImplementation = RedisTypeLocator.StackExchangeImplementation; Type redisOptions = RedisTypeLocator.StackExchangeOptions; MethodInfo initializer = RedisTypeLocator.StackExchangeInitializer; RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config); RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig, redisImplementation, redisOptions, initializer ?? null); services.Add(new ServiceDescriptor(redisInterface, factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(redisImplementation, factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RedisHealthContributor(factory, redisImplementation, ctx.GetService <ILogger <RedisHealthContributor> >()), ServiceLifetime.Singleton)); }
private static void DoAddIDistributedCache(IServiceCollection services, RedisServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, bool addSteeltoeHealthChecks = false) { var interfaceType = RedisTypeLocator.MicrosoftInterface; var connectionType = RedisTypeLocator.MicrosoftImplementation; var optionsType = RedisTypeLocator.MicrosoftOptions; var redisConfig = new RedisCacheConnectorOptions(config); var factory = new RedisServiceConnectorFactory(info, redisConfig, connectionType, optionsType, null); services.Add(new ServiceDescriptor(interfaceType, factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(connectionType, factory.Create, contextLifetime)); if (!services.Any(s => s.ServiceType == typeof(HealthCheckService)) || addSteeltoeHealthChecks) { services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RedisHealthContributor(factory, connectionType, ctx.GetService <ILogger <RedisHealthContributor> >()), ServiceLifetime.Singleton)); } }
public static IHealthContributor GetRedisContributor(IConfiguration configuration, ILogger <RedisHealthContributor> logger = null) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var redisImplementation = RedisTypeLocator.StackExchangeImplementation; var redisOptions = RedisTypeLocator.StackExchangeOptions; var initializer = RedisTypeLocator.StackExchangeInitializer; var info = configuration.GetSingletonServiceInfo <RedisServiceInfo>(); var redisConfig = new RedisCacheConnectorOptions(configuration); var factory = new RedisServiceConnectorFactory(info, redisConfig, redisImplementation, redisOptions, initializer); return(new RedisHealthContributor(factory, redisImplementation, logger)); }
private static void DoAddIDistributedCache(IServiceCollection services, RedisServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime) { Type interfaceType = RedisTypeLocator.MicrosoftRedisInterface; Type connectionType = RedisTypeLocator.MicrosoftRedisImplementation; Type optionsType = RedisTypeLocator.MicrosoftRedisOptions; if (interfaceType == null || connectionType == null || optionsType == null) { throw new ConnectorException("Unable to find required Redis types, are you missing the Microsoft.Extensions.Caching.Redis Nuget package?"); } RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config); RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig, connectionType, optionsType, null); services.Add(new ServiceDescriptor(interfaceType, factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(connectionType, factory.Create, contextLifetime)); }
private static void DoAddConnectionMultiplexer(IServiceCollection services, RedisServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, bool addSteeltoeHealthChecks) { var redisInterface = RedisTypeLocator.StackExchangeInterface; var redisImplementation = RedisTypeLocator.StackExchangeImplementation; var redisOptions = RedisTypeLocator.StackExchangeOptions; var initializer = RedisTypeLocator.StackExchangeInitializer; var redisConfig = new RedisCacheConnectorOptions(config); var factory = new RedisServiceConnectorFactory(info, redisConfig, redisImplementation, redisOptions, initializer ?? null); services.Add(new ServiceDescriptor(redisInterface, factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(redisImplementation, factory.Create, contextLifetime)); if (!services.Any(s => s.ServiceType == typeof(HealthCheckService)) || addSteeltoeHealthChecks) { services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RedisHealthContributor(factory, redisImplementation, ctx.GetService <ILogger <RedisHealthContributor> >()), ServiceLifetime.Singleton)); } }
private static void DoAddConnectionMultiplexer(IServiceCollection services, RedisServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime) { Type redisInterface = RedisTypeLocator.StackExchangeRedisInterface; Type redisImplementation = RedisTypeLocator.StackExchangeRedisImplementation; Type redisOptions = RedisTypeLocator.StackExchangeRedisOptions; MethodInfo initializer = RedisTypeLocator.StackExchangeInitializer; if (redisInterface == null || redisImplementation == null || redisOptions == null || initializer == null) { throw new ConnectorException("Unable to find required Redis types, are you missing a StackExchange.Redis Nuget Package?"); } RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config); RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig, redisImplementation, redisOptions, initializer ?? null); services.Add(new ServiceDescriptor(redisInterface, factory.Create, contextLifetime)); services.Add(new ServiceDescriptor(redisImplementation, factory.Create, contextLifetime)); }
public static IServiceCollection AddRedisConnectionMultiplexer(this IServiceCollection services, IConfiguration config) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config); RedisServiceInfo info = config.GetSingletonServiceInfo <RedisServiceInfo>(); RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig);; services.AddSingleton(typeof(ConnectionMultiplexer), factory.CreateConnection); return(services); }
public static IServiceCollection AddDistributedRedisCache(this IServiceCollection services, IConfiguration config, ILoggerFactory logFactory = null) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config); RedisServiceInfo info = config.GetSingletonServiceInfo <RedisServiceInfo>(); RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig);; services.AddSingleton(typeof(IDistributedCache), factory.CreateCache); return(services); }
public RedisHealthContributor(RedisServiceConnectorFactory factory, Type implType, ILogger <RedisHealthContributor> logger = null) { _factory = factory; _implType = implType; _logger = logger; }