public static IServiceCollection AddRedis(this IServiceCollection services, RedisOptions options) { services.TryAddSingleton(options); services.TryAddSingleton <IConnectionMultiplexer>(sp => ConnectionMultiplexer.Connect(options.ConnectionString)); services.TryAddTransient(sp => sp.GetRequiredService <IConnectionMultiplexer>().GetDatabase(options.Database)); services.AddStackExchangeRedisCache(o => { o.Configuration = options.ConnectionString; o.InstanceName = options.Instance; }); return(services); }