예제 #1
0
        public static EventStoreConfiguration ConfigureSubscriptions(this EventStoreConfiguration configuration, params Subscription[] subscriptions)
        {
            new RequestsRegistration <Disposable <List <Subscription> > >(() => new Disposable <List <Subscription> >(new List <Subscription>(subscriptions)))
            .Register <RegisteredSubscriptions, Subscription>((q, list) => list.Value);

            return(configuration);
        }
        /// <summary>
        /// Use BSON (binary JSON) for document serialization.
        /// </summary>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static EventStoreConfiguration WithBsonDocumentSerializer(this EventStoreConfiguration cfg)
        {
            IDocumentSerializer serializer = new BsonNetDocumentSerializer();

            Xyperico.Agres.EventStore.EventStoreConfigurationExtensions.SetDocumentSerializer(cfg, serializer);
            return(cfg);
        }
예제 #3
0
 public AuditLogController(
     IEventStoreReader eventStoreReader,
     EventStoreConfiguration eventStoreConfiguration)
 {
     m_EventStoreReader      = eventStoreReader;
     EventStoreConfiguration = eventStoreConfiguration;
 }
예제 #4
0
        public async Task GivenEventStore_WhenPublishingToStream_ThenWeGetEventPublished()
        {
            var configuration = new EventStoreConfiguration(
                new ConfigurationBuilder().Build()
                );

            var factory = new EventStoreClientFactory(configuration);

            using var client = factory.Create();

            var data = new List <EventData>
            {
                new TestEvent {
                    Name = "🦄",
                }.ToEventData(),
                new TestEvent {
                    Name = "bob",
                }.ToEventData(),
            };

            var results = await client.AppendToStreamAsync(
                new TestStream(),
                StreamState.Any,
                data);

            if (results == null)
            {
                Assert.Inconclusive("the current event store is empty, but we could connect");
                return;
            }

            results.NextExpectedStreamRevision.ToUInt64().Should().NotBe(ulong.MinValue);
        }
예제 #5
0
        public async Task GivenEventStore_WhenReadingStream_ThenWeGetEvents()
        {
            var configuration = new EventStoreConfiguration(
                new ConfigurationBuilder().Build()
                );

            var factory = new EventStoreClientFactory(configuration);

            using var client = factory.Create();

            var results = client.ReadStreamAsync(
                new TestStream(),
                Direction.Forwards,
                0);

            if (results == null)
            {
                Assert.Inconclusive("the current event store is empty, but we could connect");
                return;
            }

            await foreach (var e in results)
            {
                e.Should().NotBe(null);
            }
        }
        public EventsDispatcher(EventStoreConfiguration eventStoreConfiguration, IEventDataFactory eventDataFactory, IEventBus eventBus)
        {
            this._eventClrTypeHeader     = eventStoreConfiguration.EventTypeHeader;
            this._aggregateClrTypeHeader = eventStoreConfiguration.AggregateTypeHeader;

            this._eventDataFactory = eventDataFactory;
        }
예제 #7
0
        static void Main(string[] args)
        {
            var eventStoreConfiguration = new EventStoreConfiguration
            {
                MongoDbConnectionString = "mongodb://*****:*****@cluster0-shard-00-00-5pgij.mongodb.net:27017,cluster0-shard-00-01-5pgij.mongodb.net:27017,cluster0-shard-00-02-5pgij.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin",
                EventTypeHeader         = "FourSolidEventName",
                AggregateTypeHeader     = "FourSolidAggregateName"
            };

            var eventDataFactory = new EventDataFactory(eventStoreConfiguration);

            var eventStoreRepository = new EventStoreRepository(eventStoreConfiguration, eventDataFactory);

            var deviceGuid = Guid.NewGuid();
            var device     = Device.CreateDevice(deviceGuid, "AB1234DE", "AB1234DE", DateTime.UtcNow);

            eventStoreRepository.SaveAsync(device, Guid.NewGuid(), d => { }).GetAwaiter().GetResult();

            device = eventStoreRepository.GetByIdAsync <Device>(deviceGuid).GetAwaiter().GetResult();
            device.UpdateSerialNumber("BC2345EF");
            eventStoreRepository.SaveAsync(device, Guid.NewGuid(), d => { }).GetAwaiter().GetResult();

            Console.WriteLine($"Device Id: {device.Id}");
            Console.WriteLine($"Serial Number: {device.GetSerialNumber()}");
            Console.ReadLine();
        }
예제 #8
0
        internal static ContainerBuilder RegisterModules()
        {
            var eventStoreConfiguration = new EventStoreConfiguration(
                EvenstDispatcherConfiguration.EventStoreSection.Uri,
                EvenstDispatcherConfiguration.EventStoreSection.Port,
                EvenstDispatcherConfiguration.EventStoreSection.User,
                EvenstDispatcherConfiguration.EventStoreSection.Password,
                "",
                "");

            var rmqParameters = new RmqParameters
                                (
                EvenstDispatcherConfiguration.RabbitMqSection.Uri,
                EvenstDispatcherConfiguration.RabbitMqSection.HostName,
                EvenstDispatcherConfiguration.RabbitMqSection.Username,
                EvenstDispatcherConfiguration.RabbitMqSection.Password,
                EvenstDispatcherConfiguration.RabbitMqSection.Events,
                24
                                );

            var builder = new ContainerBuilder();

            builder.RegisterType <EventBus>().As <IEventBus>().SingleInstance();
            builder.RegisterModule(new RabbitMqModule(rmqParameters));
            builder.RegisterModule(new EventStoreModule(eventStoreConfiguration));
            builder.RegisterType <DocumentUnitOfWork>().As <IDocumentUnitOfWork>().InstancePerDependency();
            builder.RegisterType <LogService>().As <ILogService>().InstancePerDependency();
            builder.RegisterType <EventsFactory>().As <IEventsFactory>().InstancePerDependency();

            return(builder);
        }
        internal static ContainerBuilder RegisterModules(IConfiguration configuration)
        {
            //TODO: I don't know if it's the best practice, but it works, and it's enough for me!
            var eventStoreConfiguration = new EventStoreConfiguration
                                          (
                configuration["4Solid:EventStoreParameters:Uri"],
                int.Parse(configuration["4Solid:EventStoreParameters:Port"]),
                configuration["4Solid:EventStoreParameters:User"],
                configuration["4Solid:EventStoreParameters:Password"],
                configuration["4Solid:EventStoreParameters:EventClrTypeHeader"],
                configuration["4Solid:EventStoreParameters:AggregateClrTypeHeader"]
                                          );

            var builder = new ContainerBuilder();

            builder.RegisterModule(new EventStoreModule(eventStoreConfiguration));

            builder.RegisterModule <InProcessBusModule>();

            builder.RegisterModule <FactoryModule>();
            builder.RegisterModule <CommandsModule>();
            builder.RegisterModule <MappersModule>();
            builder.RegisterModule <EventsModule>();
            builder.RegisterModule <InstantiateCommandProcessor>();

            builder.RegisterModule <ServicesModule>();

            builder.RegisterModule <ReadModelModule>();

            return(builder);
        }
        /// <summary>
        /// Use JSON for event serialization.
        /// </summary>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static EventStoreConfiguration WithJsonEventSerializer(this EventStoreConfiguration cfg)
        {
            ISerializer serializer = new JsonNetSerializer();

            Xyperico.Agres.EventStore.EventStoreConfigurationExtensions.SetMessageSerializer(cfg, serializer);
            return(cfg);
        }
        public EventStoreRepository(EventStoreConfiguration eventStoreConfiguration, IEventDataFactory eventDataFactory)
            : this((t, g) => $"{char.ToLower(t.Name[0])}{t.Name.Substring(1)}Events-{g}")
        {
            this._eventClrTypeHeader     = eventStoreConfiguration.EventTypeHeader;
            this._aggregateClrTypeHeader = eventStoreConfiguration.AggregateTypeHeader;

            this._eventDataFactory = eventDataFactory;
        }
예제 #12
0
        public static EventStoreConfiguration ConfigureSubscriptions(this EventStoreConfiguration configuration, params IEnumerable <Subscription>[] subscriptions)
        {
            configuration.ConfigureSubscriptions(subscriptions
                                                 .SelectMany(x => x)
                                                 .ToArray());

            return(configuration);
        }
예제 #13
0
 public static IDisposable StartHost <TEventStoreConnectionStringName, THangfireDatabaseConnectionStringName>(
     this EventStoreConfiguration <TEventStoreConnectionStringName> configuration)
     where TEventStoreConnectionStringName : class where THangfireDatabaseConnectionStringName : class
 {
     return(new HangfireSubscriberHost <TEventStoreConnectionStringName, THangfireDatabaseConnectionStringName>
            (
                () => Request <Subscriber> .By(new ConfiguredSubscribers())
            ));
 }
예제 #14
0
        internal static ContainerBuilder RegisterModules()
        {
            var builder = new ContainerBuilder();

            #region ILogger
            var serviceProvider = new ServiceCollection()
                                  .AddLogging()
                                  .BuildServiceProvider();
            var factory = serviceProvider.GetService <ILoggerFactory>();
            var articoloFactoryLogger = factory.CreateLogger <ArticoloFactory>();

            builder.RegisterInstance(articoloFactoryLogger);
            #endregion

            #region IOptions
            IOptions <FourSettings> options = Options.Create(new FourSettings
            {
                EventStoreParameters = new EventStoreParameters
                {
                    Uri      = "127.0.0.1",
                    Port     = 1113,
                    User     = "******",
                    Password = "******"
                },
                MongoDbParameters = new MongoDbParameters
                {
                    ConnectionString = "mongodb://*****:*****@cluster0-shard-00-00-5pgij.mongodb.net:27017,cluster0-shard-00-01-5pgij.mongodb.net:27017,cluster0-shard-00-02-5pgij.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin"
                }
            });
            builder.RegisterInstance(options);
            #endregion

            var eventStoreConfiguration = new EventStoreConfiguration
                                          (
                options.Value.EventStoreParameters.Uri,
                options.Value.EventStoreParameters.Port,
                options.Value.EventStoreParameters.User,
                options.Value.EventStoreParameters.Password,
                "4SolidEvents", "4SolidAggregates"
                                          );
            builder.RegisterModule(new EventStoreModule(eventStoreConfiguration));

            builder.RegisterModule <InProcessBusModule>();

            builder.RegisterModule <FactoryModule>();
            builder.RegisterModule <CommandsModule>();
            builder.RegisterModule <MappersModule>();
            builder.RegisterModule <EventsModule>();
            builder.RegisterModule <InstantiateCommandProcessor>();

            builder.RegisterModule <ServicesModule>();

            builder.RegisterModule <ReadModelModule>();

            return(builder);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            ServiceConfiguration.configure(Configuration, services);
            RabbitMqConfiguration.configure(Configuration, services);
            ReservaClienteConfiguration.configure(Configuration, services);
            EventStoreConfiguration.configure(Configuration, services);

            services.AddCors();
        }
예제 #16
0
        public static IConfigure UsingOracleEventStore(this IEventsConfiguration eventsConfiguration, Action <EventStoreConfiguration> configureCallback)
        {
            eventsConfiguration.EventStoreType = typeof(EventStore);
            var configuration = new EventStoreConfiguration();

            configureCallback(configuration);

            Configure.Instance.Container.Bind(configuration);
            return(Configure.Instance);
        }
예제 #17
0
        public static IEventStoreConnection Connect(EventStoreConfiguration config, string port, string connectionName = null, bool keepReconnecting = true)
        {
            var settings = ConnectionSettings.Create();

            if (keepReconnecting)
            {
                settings.KeepReconnecting();
            }
            return(Connect(settings, config, port, connectionName));
        }
예제 #18
0
        private static void WithEventStoreDatabase(this ContainerBuilder builder, EventStoreConfiguration config)
        {
            var connection = EventStoreConnection.Create(new IPEndPoint(
                                                             address: IPAddress.Parse(config.Host),
                                                             port: config.Port
                                                             ));

            connection.ConnectAsync().Wait();
            builder.RegisterInstance(connection).AsImplementedInterfaces().SingleInstance();
        }
예제 #19
0
        public static EventStoreConfiguration <TSubscriptionStoreConnectionStringName> ConfigureSubscriptions <TSubscriptionStoreConnectionStringName>(
            this EventStoreConfiguration <TSubscriptionStoreConnectionStringName> configuration,
            Func <IDbConnection, IEnumerable <Subscription> > subscriptionQuery)
            where TSubscriptionStoreConnectionStringName : class
        {
            new RequestsRegistration <IDbConnection>(() => new SqlConnection(ConnectionString.ByName(typeof(TSubscriptionStoreConnectionStringName).FriendlyName())).With(x => x.Open()))
            .Register <RegisteredSubscriptions, Subscription>((q, connection) => subscriptionQuery(connection));

            return(configuration);
        }
        /// <summary>
        /// Use SQLite for backend append-only store.
        /// </summary>
        /// <param name="cfg"></param>
        /// <param name="connectionString"></param>
        /// <param name="createTable"></param>
        /// <returns></returns>
        public static EventStoreConfiguration WithSQLiteEventStore(this EventStoreConfiguration cfg, string connectionString, bool createTable)
        {
            if (createTable)
            {
                SQLiteAppendOnlyStore.CreateTableIfNotExists(connectionString);
            }
            IAppendOnlyStore aStore = new SQLiteAppendOnlyStore(connectionString);

            Xyperico.Agres.EventStore.EventStoreConfigurationExtensions.SetAppendOnlyStore(cfg, aStore);
            return(cfg);
        }
        public void Should_be_able_to_add_and_check_for_active_projection_names()
        {
            var configuration = new EventStoreConfiguration();

            Assert.That(configuration.HasActiveProjection("not-registered"), Is.True);

            configuration.AddActiveProjectionName("projection-1");

            Assert.That(configuration.HasActiveProjection("not-registered"), Is.False);
            Assert.That(configuration.HasActiveProjection("projection-1"), Is.True);
        }
 public static UserCredentials Config(EventStoreConfiguration config)
 {
     if (string.IsNullOrEmpty(config.Username))
     {
         return(Credentials);
     }
     else
     {
         return(new UserCredentials(config.Username, config.Password));
     }
 }
예제 #23
0
        /// <summary>
        /// Initializes an instance of <see cref="EventsConfiguration"/>
        /// </summary>
        public EventsConfiguration()
        {
            CommittedEventStreamSender   = new CommittedEventStreamSenderConfiguration();
            CommittedEventStreamReceiver = new CommittedEventStreamReceiverConfiguration();
            EventProcessorLog            = typeof(NullEventProcessorLog);

            EventStore           = new EventStoreConfiguration();
            EventSourceVersions  = new EventSourceVersionsConfiguration();
            EventSequenceNumbers = new EventSequenceNumbersConfiguration();
            EventProcessorStates = new EventProcessorStatesConfiguration();
        }
예제 #24
0
        private static EventStoreConfiguration GetESConfiguration(IServiceCollection services)
        {
            using var serviceProvider = services.BuildServiceProvider();

            var configuration = serviceProvider.GetService <IConfiguration>();
            var esConfig      = new EventStoreConfiguration();

            configuration.Bind("EventStore", esConfig);

            return(esConfig);
        }
예제 #25
0
        public static EventStoreConfiguration ConfigureTransport <THangfireConnectionStringName>(
            this EventStoreConfiguration config)
            where THangfireConnectionStringName : class
        {
            Initialize <THangfireConnectionStringName>();

            PostBox <AdoNetTransactionScopeUowProvider> .CommitWork = AdoNetTransactionScopeUowProvider.Commit();

            PostBox <AdoNetTransactionScopeUowProvider> .Enqueue = Enqueue;

            return(config);
        }
예제 #26
0
 public static EventStoreConfiguration ConfigureMessageHandler(this EventStoreConfiguration config)
 {
     JsonMessageHandler.HandleInstance =
         m =>
     {
         foreach (var subscriber in Request <Subscriber> .By(new ConfiguredSubscribers()))
         {
             subscriber(m);
         }
     };
     return(config);
 }
예제 #27
0
        public static IEventSourcingConfiguration WithEventStoreAsES(
            this IEventSourcingConfiguration configuration
            )
        {
            return(configuration.WithEventStore <EventStore.EventStore>((builder, config) =>
            {
                var eventStoreConfig = new EventStoreConfiguration(config);

                builder.WithEventStoreDatabase(eventStoreConfig);
                builder.RegisterType <EventConverter>().AsSelf().SingleInstance();
            }));
        }
예제 #28
0
        public void GivenAFactory_WhenCreatingACLient_thenAClientIsInstantiated()
        {
            var configuration = new EventStoreConfiguration(
                new ConfigurationBuilder().Build()
                );

            var factory = new EventStoreClientFactory(configuration);

            var client = factory.Create();

            client.Should().NotBeNull();
        }
        public void GivenEmptyConfiguration_WhenBuilding_ThenWeGetDefaults()
        {
            var configuration = new EventStoreConfiguration(
                new ConfigurationBuilder().Build()
                );

            configuration.HostName.Should().Be("localhost");
            configuration.Protocol.Should().Be("http");
            configuration.Username.Should().Be("admin");
            configuration.Password.Should().Be("changeit");
            configuration.IsClusterModeEnabled.Should().Be(false);
        }
예제 #30
0
        public static EventStoreAzureDbConfiguration GetEventStoreConfig()
        {
            var config = new EventStoreConfiguration
            {
                EndPointUrl = System.Environment.GetEnvironmentVariable(URL),
                DatabaseId  = System.Environment.GetEnvironmentVariable(DATABASE),
                AuthKey     = System.Environment.GetEnvironmentVariable(AUTHKEY)
            };
            var configurationFor = new Mock <IConfigurationFor <EventStoreConfiguration> >();

            configurationFor.SetupGet(_ => _.Instance).Returns(config);
            return(new EventStoreAzureDbConfiguration(configurationFor.Object, GetLogger(), GetExecutionContext()));
        }