private static EventStoreSettings CreateCustomSettings(Action <EventStoreSettings> setupAction)
        {
            var settings = new EventStoreSettings();

            setupAction(settings);
            return(settings);
        }
Example #2
0
        public static EventStoreSettings EventStoreSettings(ITestOutputHelper h)
        {
            Logger(h);

            var f = new EventStoreSettings();

            return(f);
        }
Example #3
0
 public MigratingEventsFacadeStoreTests(ITestOutputHelper h)
 {
     _store    = Substitute.For <ISpecificDbStorage>();
     _settings = Setup.EventStoreSettings(h);
     _sut      = new StoreFacade(_store, _settings);
     _dest     = Substitute.For <IStoreEvents>();
     _importer = new FakeImport();
     _dest.Advanced.Returns(_importer);
 }
Example #4
0
 private static void ApplyEventStoreSettings(EventStoreSettings settings)
 {
     // TODO: Pull from config
     settings.EndPoint = new IPEndPoint(IPAddress.Loopback, 1113);
     settings.EventTypes["QuestionAskedEvent"]    = typeof(QuestionAskedEvent);
     settings.EventTypes["QuestionTaggedEvent"]   = typeof(QuestionTaggedEvent);
     settings.EventTypes["QuestionAnsweredEvent"] = typeof(QuestionAnsweredEvent);
     settings.EventTypes["QuestionLikedEvent"]    = typeof(QuestionLikedEvent);
     settings.EventTypes["AnswerAcceptedEvent"]   = typeof(AnswerAcceptedEvent);
 }
Example #5
0
        public RedisMessageQueue(IRedisClient redis, EventStoreSettings settings, string environment)
        {
            if (string.IsNullOrWhiteSpace(settings.KeyPrefix))
            {
                throw new ArgumentException("KeyPrefix must be specified in EventStoreSettings");
            }

            _redis       = redis;
            _settings    = settings;
            _environment = environment;
        }
Example #6
0
 public Session(IRepository repository, EventStoreSettings eventStoreSettings, IDistributedLockFactory distributedLockFactory)
 {
     _repository         = repository ?? throw new ArgumentNullException(nameof(repository));
     _trackedAggregates  = new Dictionary <string, AggregateDescriptor>();
     _eventStoreSettings = eventStoreSettings;
     if (eventStoreSettings != null && eventStoreSettings.SessionLockEnabled)
     {
         _sessionLockEnabled     = true;
         _distributedLockFactory = distributedLockFactory ?? throw new ArgumentNullException(nameof(distributedLockFactory));
     }
 }
        public RedisEventStore(IRedisClient redis, EventStoreSettings settings, IMessageQueue messageQueue)
        {
            if (string.IsNullOrWhiteSpace(settings.KeyPrefix))
            {
                throw new ArgumentException("KeyPrefix must be specified in EventStoreSettings");
            }

            _redis        = redis;
            _settings     = settings;
            _messageQueue = messageQueue;
        }
Example #8
0
        public RedisSnapshotStore(IRedisClient redis, EventStoreSettings settings)
        {
            if (string.IsNullOrWhiteSpace(settings.KeyPrefix))
            {
                throw new ArgumentException("KeyPrefix must be specified in EventStoreSettings");
            }

            _redis       = redis;
            _settings    = settings;
            _hashKeyBase = $"Snapshots:{_settings.KeyPrefix}";
        }
 public EventStoreSubscriptionHost(
     IEventStoreConnection eventStore,
     IJsonByteConverter jsonByteConverter,
     EventStoreSettings eventStoreSettings,
     ILogger <EventStoreSubscriptionHost> logger)
 {
     _eventStore         = eventStore;
     _jsonByteConverter  = jsonByteConverter;
     _eventStoreSettings = eventStoreSettings;
     _logger             = logger;
 }
Example #10
0
 public TestSqlEventStore(
     EventStoreSettings settings,
     ISqlStatementsLoader sqlStatementsLoader,
     IDbConnectionFactory connectionFactory,
     IEventDataSerializer <TSerializationType> eventDataSerializer)
     : base(
         settings,
         sqlStatementsLoader,
         connectionFactory,
         eventDataSerializer)
 {
 }
Example #11
0
        protected SqlEventStore(
            EventStoreSettings settings,
            ISqlStatementsLoader sqlStatementsLoader,
            IDbConnectionFactory connectionFactory,
            IEventDataSerializer <TSerializationType> eventDataSerializer)
        {
            ConnectionString = settings.ConnectionStrings["EventStore"];

            SqlStatementsLoader = sqlStatementsLoader;
            ConnectionFactory   = connectionFactory;

            EventDataSerializer = eventDataSerializer;
        }
Example #12
0
        public void ThrowsArgumentExceptionIfEventStoreSettingsConstructorIsUsedAndKeyPrefixIsNotSet()
        {
            var settings = new EventStoreSettings();

            try
            {
                new DataStores.RedisEventStore(_redis, settings, _messageQueue);
                Assert.Fail("Should have thrown ArgumentException");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual("KeyPrefix must be specified in EventStoreSettings", 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 EventStoreSettings
            {
                KeyPrefix         = 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);
        }
 private static void ApplyDefaultSettings(EventStoreSettings settings)
 {
     settings.NamingPreferences = EventStoreNamingConvention.Literal;
     settings.EndPoint          = new IPEndPoint(IPAddress.Loopback, 1113);
 }
Example #15
0
        public static IEventFlowOptions ConfigureEventStore(this IEventFlowOptions options, EventStoreSettings settings)
        {
            Uri eventStoreUri = GetUriFromConnectionString(settings.ConnectionString);

            var connectionSettings = ConnectionSettings.Create()
                                     .EnableVerboseLogging()
                                     .KeepReconnecting()
                                     .KeepRetrying()
                                     .SetDefaultUserCredentials(new UserCredentials(settings.Username, settings.Password))
                                     .Build();

            IEventFlowOptions eventFlowOptions = options
                                                 .AddMetadataProvider <AddGuidMetadataProvider>()
                                                 .UseEventStoreEventStore(eventStoreUri, connectionSettings);

            return(eventFlowOptions);
        }
Example #16
0
 public EventStoreRepository(Context context, IMediator mediator, IOptions <EventStoreSettings> options)
 {
     _context  = context;
     _mediator = mediator;
     _settings = options.Value;
 }
Example #17
0
        public static IServiceCollection AddEventStore(
            this IServiceCollection services,
            EventStoreSettings settings,
            ILoggerFactory loggerFactory)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (settings.Store == null)
            {
                throw new ArgumentException("Store settings not specified.", nameof(settings.Store));
            }

            if (settings.AggregateFactories == null)
            {
                throw new ArgumentException("Factories not specified.", nameof(settings.AggregateFactories));
            }

            var compositeContext = new CompositeEventStoreContext(settings.Store.Contexts);
            var typesRegistry    = new EventTypeRegistry(settings.Store.Connections, compositeContext);

            InitializeSchemas(settings.Store, typesRegistry);

            var reader = new EventsReader(settings.Store.Connections, compositeContext, typesRegistry);

            var eventStore = new Postgres.EventStore(
                reader,
                new EventsWriter(settings.Store.Connections, compositeContext, typesRegistry,
                                 new EventsOutbox(compositeContext, reader),
                                 loggerFactory.CreateLogger <EventsWriter>())
                );

            var backgroundPublisher = new OutboxPublisherService(
                new OutboxPublisher(
                    settings.Store.Connections,
                    settings.Store.Contexts,
                    reader),
                settings.Store.OutboxInterval,
                loggerFactory.CreateLogger <OutboxPublisherService>());

            services
            .AddAggregates(settings.AggregateFactories)
            .AddStreamResolver(settings.Store.Serializer)
            .AddSingleton <IEventStore>(eventStore)
            .AddSingleton <IHostedService>(backgroundPublisher);

            if (settings.Snapshots == null)
            {
                return(services);
            }

            return(services.AddSnapshotStore(
                       settings.Snapshots,
                       settings.Store.Connections,
                       compositeContext, loggerFactory));
        }
Example #18
0
 public EventsSubscriber(IServiceProvider serviceProvider, IEventStoreConnection connection, IOptions <EventStoreSettings> eventStoreOptions)
 {
     _serviceProvider    = serviceProvider;
     _connection         = connection;
     _eventStoreSettings = eventStoreOptions.Value;
 }
Example #19
0
 internal MongoEventStore(IMongoFacade db, EventStoreSettings settings, BatchIDGenerator idGenerator) : this(db, settings)
 {
     _idGenerator = idGenerator;
 }
Example #20
0
 internal EventStoreConfigurator()
 {
     Settings = new EventStoreSettings();
 }
Example #21
0
 public MongoEventStore(IMongoFacade db, EventStoreSettings settings)
 {
     _db      = Check.NotNull(db, nameof(db));
     _streams = new StreamCollection(settings.Streams);
 }