public DataFactory(DataFactoryOptions options, IConfiguration config) { //Conexão com o redis. string redisServer = "localhost:6379"; if (config != null) { redisServer = config.GetConnectionString(options.RedisConnectionStringName); } _lazyRedisClient = new Lazy <ConnectionMultiplexer>(() => { var redisOptions = ConfigurationOptions.Parse(redisServer); redisOptions.AbortOnConnectFail = false; return(ConnectionMultiplexer.Connect(redisOptions)); }, LazyThreadSafetyMode.ExecutionAndPublication); //Criação do RedLockFactory var existingConnectionMultiplexer1 = ConnectionMultiplexer.Connect(redisServer); var multiplexers = new List <RedLockMultiplexer> { existingConnectionMultiplexer1 }; _redLockFactory = RedLockFactory.Create(multiplexers); }
private static void AddDataFactory(this IServiceCollection services) { services.TryAddSingleton(sp => { var config = sp.GetService <IConfiguration>(); var dataFactoryOptions = new DataFactoryOptions(); return(new DataFactory(dataFactoryOptions, config)); }); }