public RedisEventStore(IRedisClient redis, RedisEventStoreSettings settings, IMessageQueue messageQueue) { if (string.IsNullOrWhiteSpace(settings.ApplicationName)) { throw new ArgumentException("ApplicationName must be specified in RedisEventStoreSettings"); } _redis = redis; _settings = settings; _messageQueue = messageQueue; }
public void ThrowsArgumentExceptionIfEventStoreSettingsConstructorIsUsedAndApplicationNameIsNotSet() { var settings = new RedisEventStoreSettings(); try { new DataStores.RedisEventStore(_redis, settings, _messageQueue); Assert.Fail("Should have thrown ArgumentException"); } catch (ArgumentException e) { Assert.AreEqual("ApplicationName must be specified in RedisEventStoreSettings", e.Message); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // Add Cqrs services LoadQueryHandler(typeof(IQueryHandler <,>), services); LoadQueryHandler(typeof(IAsyncQueryHandler <,>), services); LoadCommandHandler(typeof(ICommandHandler <>), services); LoadCommandHandler(typeof(IAsyncCommandHandler <>), services); services.AddScoped <IHub>(c => new Hub(c.GetService)); // Configure Redis Connection var redisConfigOptions = ConfigurationOptions.Parse("127.0.0.1:6379"); redisConfigOptions.AbortOnConnectFail = false; services.AddSingleton(new Lazy <IConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(redisConfigOptions))); // Set up EventStore var keyPrefix = "Learning.EventStore.Sample.Web"; services.AddMemoryCache(); var eventStoreSettings = new RedisEventStoreSettings { ApplicationName = keyPrefix, EnableCompression = false }; services.AddSingleton <IRedisClient>(y => new RedisClient(y.GetService <Lazy <IConnectionMultiplexer> >())); services.AddSingleton <IEventSubscriber>(y => new RedisEventSubscriber(y.GetService <IRedisClient>(), keyPrefix, y.GetService <IHostingEnvironment>().EnvironmentName, y.GetService <ILoggerFactory>())); services.AddScoped <ISession, Session>(); services.AddSingleton <IMessageQueue>(y => new RedisMessageQueue(y.GetService <IRedisClient>(), keyPrefix, y.GetService <IHostingEnvironment>().EnvironmentName)); services.AddSingleton <IEventStore>(y => new RedisEventStore(y.GetService <IRedisClient>(), eventStoreSettings, y.GetService <IMessageQueue>())); services.AddSingleton <ICache, MemoryCache>(); services.AddScoped <IRepository>(y => new Repository(y.GetService <IEventStore>())); // Register subscriptions var serviceProvider = services.BuildServiceProvider(); LoadSubscriptionHandlers(serviceProvider); }