Пример #1
0
        public async Task <MySqlStreamStore> GetMySqlStreamStore()
        {
            await CreateDatabase();

            var settings = new MySqlStreamStoreSettings(ConnectionString);

            var mySqlStreamStore = new MySqlStreamStore(settings);
            await mySqlStreamStore.CreateSchemaIfNotExists();

            return(mySqlStreamStore);
        }
Пример #2
0
        private async Task <IStreamStore> GetMySqlStore(bool dropAll)
        {
            var store = new MySqlStreamStore(new MySqlStreamStoreSettings(Configuration.MySqlConnectionString));

            if (dropAll)
            {
                store.DropAll().Wait();
            }
            if (dropAll || !store.CheckSchema().Result.IsMatch)
            {
                store.CreateSchemaIfNotExists().Wait();
            }

            return(store);
        }
        public static IServiceCollection AddMySqlEventStore(this IServiceCollection services,
                                                            Action <MySqlOptions>?mysqlOptions = null, Action <MySqlEventSourcingOptions>?eventSourcingOptions = null)
        {
            var options = new MySqlEventSourcingOptions();

            eventSourcingOptions?.Invoke(options);

            services.AddMySqlData(mysqlOptions)
            .AddEventStore(eventSourcingOptionsAccessor: o => o = options)
            .AddSingleton <MySqlCheckpointManager>();

            var serviceProvider = services.BuildServiceProvider();

            if (!(serviceProvider.GetService <IStreamStore>() is MySqlStreamStore))
            {
                services.AddSingleton <IStreamStore>(sp =>
                {
                    var connectionString = sp.GetRequiredService <IMySqlConnection>().Build().ConnectionString;
                    var streamStore      = new MySqlStreamStore(new MySqlStreamStoreSettings(connectionString));

                    if (!options.CreateSchemaIfNotExists)
                    {
                        return(streamStore);
                    }

                    streamStore.CreateSchemaIfNotExists().Wait();
                    sp.GetRequiredService <MySqlCheckpointManager>().CreateSchemaIfNotExists().Wait();

                    return(streamStore);
                });
            }

            services.TryAddSingleton <GetGlobalCheckpoint>(sp =>
                                                           sp.GetRequiredService <MySqlCheckpointManager>().GetGlobalCheckpoint);

            services.TryAddSingleton <SetGlobalCheckpoint>(sp =>
                                                           sp.GetRequiredService <MySqlCheckpointManager>().SetGlobalCheckpoint);

            return(services);
        }