Example #1
0
 private static IEventFlowOptions ConfigureFirebase(
     this IEventFlowOptions eventFlowOptions,
     Func <IFirebaseClient> firebaseClientFactory, bool useBackupStore)
 {
     if (useBackupStore)
     {
         return(eventFlowOptions.RegisterServices(sr =>
         {
             sr.Register(f => firebaseClientFactory(), Lifetime.Singleton);
             sr.Register <IReadModelDescriptionProvider, ReadModelDescriptionProvider>(Lifetime.Singleton, true);
             sr.Register <IReadModelBackUpStore, ReadModelBackUpStore>();
             sr.Register <IFirebaseReadStoreConfiguration>(f => new FirebaseReadStoreConfiguration(useBackupStore), Lifetime.Singleton);
         }));
     }
     else
     {
         return(eventFlowOptions.RegisterServices(sr =>
         {
             sr.Register(f => firebaseClientFactory(), Lifetime.Singleton);
             sr.Register <IReadModelDescriptionProvider, ReadModelDescriptionProvider>(Lifetime.Singleton, true);
             sr.Register <IReadModelBackUpStore, MockReadModelBackUpStore>();
             sr.Register <IFirebaseReadStoreConfiguration>(f => new FirebaseReadStoreConfiguration(useBackupStore), Lifetime.Singleton);
         }));
     }
 }
Example #2
0
        public AspNetCoreEventFlowOptions AddUserClaimsMetadata(params string[] includedClaimTypes)
        {
            var options = new DefaultUserClaimsMetadataOptions(includedClaimTypes);

            _options.RegisterServices(s => s.Register <IUserClaimsMetadataOptions>(_ => options));
            return(RegisterMetadataProvider <AddUserClaimsMetadataProvider>());
        }
        public static IEventFlowOptions UseEventStoreEventStore(
            this IEventFlowOptions eventFlowOptions,
            Uri uri,
            ConnectionSettings connectionSettings,
            string connectionNamePrefix = null)
        {
            var sanitizedConnectionNamePrefix = string.IsNullOrEmpty(connectionNamePrefix)
                ? string.Empty
                : connectionNamePrefix + " - ";

            var eventStoreConnection = EventStoreConnection.Create(
                connectionSettings,
                uri,
                $"{sanitizedConnectionNamePrefix}EventFlow v{typeof(EventFlowOptionsExtensions).Assembly.GetName().Version}");

#pragma warning disable 618
            // TODO: Figure out bootstrapping alternative for 1.0
            using (var a = AsyncHelper.Wait)
            {
                a.Run(eventStoreConnection.ConnectAsync());
            }
#pragma warning restore 618

            return(eventFlowOptions
                   .RegisterServices(f => f.Register(r => eventStoreConnection, Lifetime.Singleton))
                   .UseEventStore <EventStoreEventPersistence>());
        }
 public static IEventFlowOptions AddAspNetCoreMetadataProviders(
     this IEventFlowOptions eventFlowOptions)
 {
     return(eventFlowOptions
            .RegisterServices(sr => sr.Register(typeof(IHttpContextAccessor), typeof(HttpContextAccessor), Lifetime.Singleton))
            .AddMetadataProviders(EventFlowAspNetCore.Assembly));
 }
Example #5
0
        public static IEventFlowOptions AddQueryHandlers(
            this IEventFlowOptions eventFlowOptions,
            IEnumerable <Type> queryHandlerTypes)
        {
            foreach (var queryHandlerType in queryHandlerTypes)
            {
                var t = queryHandlerType;
                var queryHandlerInterfaces = t
                                             .GetInterfaces()
                                             .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler <,>))
                                             .ToList();
                if (!queryHandlerInterfaces.Any())
                {
                    throw new ArgumentException($"Type '{t.PrettyPrint()}' is not an '{typeof(IQueryHandler<,>).PrettyPrint()}'");
                }

                eventFlowOptions.RegisterServices(sr =>
                {
                    foreach (var queryHandlerInterface in queryHandlerInterfaces)
                    {
                        sr.Register(queryHandlerInterface, t);
                    }
                });
            }

            return(eventFlowOptions);
        }
 public static IEventFlowOptions UseSnapshotStore<TSnapshotStore>(
     this IEventFlowOptions eventFlowOptions,
     Lifetime lifetime = Lifetime.AlwaysUnique)
     where TSnapshotStore : class, ISnapshotPersistence
 {
     return eventFlowOptions.RegisterServices(sr => sr.Register<ISnapshotPersistence, TSnapshotStore>(lifetime));
 }
Example #7
0
        public static IEventFlowOptions UseStreamsDbEventStore(
            this IEventFlowOptions eventFlowOptions,
            string connectionString,
            string service)
        {
            StreamsDBClient client = null;

            using (var a = AsyncHelper.Wait)
            {
                a.Run(StreamsDBClient.Connect(connectionString), c => client = c);
            }

            return(eventFlowOptions
                   .RegisterServices(f =>
            {
                f.Register(r => client, Lifetime.Singleton);
                f.Register <NullReadModelLocator, NullReadModelLocator>();

                // todo: move to own extension method
                //f.Register<IStreamsDbMessageFactory, StreamsDbMessageFactory>(Lifetime.Singleton);
                //f.Register<IStreamsDbPublisher, StreamsDbPublisher>(Lifetime.Singleton);
                //f.Register<ISubscribeSynchronousToAll, StreamsDbDomainEventPublisher>();

                // f.Register(rc => new StreamsDbServiceConfiguration(service), Lifetime.Singleton);
            })
                   //.AddMetadataProvider<ServiceMetadataProvider>()
                   .UseEventStore <StreamsDbEventPersistence>());
        }
Example #8
0
 public static IEventFlowOptions IncludeLocations(this IEventFlowOptions eventFlowOptions)
 {
     return(eventFlowOptions
            .RegisterServices(sr => { sr.RegisterType(typeof(Invitations)); })
            .UseEntityFrameworkReadModel <Location, ApplicationContext>()
            .UseEntityFrameworkReadModel <Invitation, ApplicationContext, Invitations>());
 }
Example #9
0
 private static void registerCommon(IEventFlowOptions options, ILxSettings configuration)
 {
     options.RegisterServices(sr =>
     {
         sr.Register(rc => configuration, Lifetime.Singleton);
     });
 }
 public static IEventFlowOptions UseEventStore <TEventStore>(
     this IEventFlowOptions eventFlowOptions,
     Lifetime lifetime = Lifetime.AlwaysUnique)
     where TEventStore : class, IEventPersistence
 {
     return(eventFlowOptions.RegisterServices(f => f.Register <IEventPersistence, TEventStore>(lifetime)));
 }
        public static IEventFlowOptions UseEventStoreEventStore(
            this IEventFlowOptions eventFlowOptions,
            Uri uri,
            ConnectionSettings connectionSettings,
            string connectionNamePrefix = null)
        {
            var sanitizedConnectionNamePrefix = string.IsNullOrEmpty(connectionNamePrefix)
                ? string.Empty
                : connectionNamePrefix + " - ";

            var eventStoreConnection = EventStoreConnection.Create(
                connectionSettings,
                uri,
                $"{sanitizedConnectionNamePrefix}EventFlow v{typeof(EventFlowOptionsExtensions).Assembly.GetName().Version}");

            using (var a = AsyncHelper.Wait)
            {
                a.Run(eventStoreConnection.ConnectAsync());
            }

            return(eventFlowOptions
                   .RegisterServices(f => f.Register(r => eventStoreConnection, Lifetime.Singleton))
                   .RegisterServices(f => f.Register <IEventPersistence, EventStoreEventPersistence>())
                   .RegisterServices(f => f.Register <IEventStore, EventStoreBase>())
                   .RegisterServices(f => f.Register <IEventPersistence, EventStoreEventPersistence>()));
        }
        protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
        {
            _elasticsearchUrl = Environment.GetEnvironmentVariable("ELASTICSEARCH_URL");
            _indexName        = $"eventflow-test-{Guid.NewGuid():D}";

            var testReadModelDescriptionProvider = new TestReadModelDescriptionProvider(_indexName);

            var resolver = eventFlowOptions
                           .RegisterServices(sr =>
            {
                sr.RegisterType(typeof(ThingyMessageLocator));
                sr.Register <IReadModelDescriptionProvider>(c => testReadModelDescriptionProvider);
            })
                           .ConfigureElasticsearch(_elasticsearchUrl)
                           .UseElasticsearchReadModelFor <ThingyAggregate, ThingyId, ElasticsearchThingyReadModel>()
                           .UseElasticsearchReadModel <ElasticsearchThingyMessageReadModel, ThingyMessageLocator>()
                           .AddQueryHandlers(
                typeof(ElasticsearchThingyGetQueryHandler),
                typeof(ElasticsearchThingyGetVersionQueryHandler),
                typeof(ElasticsearchThingyGetMessagesQueryHandler))
                           .CreateResolver();

            _elasticClient = resolver.Resolve <IElasticClient>();

            _elasticClient.CreateIndex(_indexName, c => c
                                       .Settings(s => s
                                                 .NumberOfShards(1)
                                                 .NumberOfReplicas(0))
                                       .Mappings(m => m
                                                 .Map <ElasticsearchThingyMessageReadModel>(d => d
                                                                                            .AutoMap())));

            return(resolver);
        }
Example #13
0
 public static IEventFlowOptions UsePermanentMemoryCache(
     this IEventFlowOptions eventFlowOptions)
 {
     return
         (eventFlowOptions.RegisterServices(
              r => r.Register <IMemoryCache, DictionaryMemoryCache>(Lifetime.Singleton)));
 }
Example #14
0
        public static IEventFlowOptions AddCommandHandlers(
            this IEventFlowOptions eventFlowOptions,
            IEnumerable <Type> commandHandlerTypes)
        {
            foreach (var commandHandlerType in commandHandlerTypes)
            {
                var t = commandHandlerType;
                if (t.GetTypeInfo().IsAbstract)
                {
                    continue;
                }
                var handlesCommandTypes = t
                                          .GetTypeInfo()
                                          .GetInterfaces()
                                          .Where(
                    i =>
                    i.GetTypeInfo().IsGenericType&&
                    i.GetGenericTypeDefinition() == typeof(ICommandHandler <, , ,>))
                                          .ToList();
                if (!handlesCommandTypes.Any())
                {
                    throw new ArgumentException(
                              $"Type '{commandHandlerType.PrettyPrint()}' does not implement '{typeof(ICommandHandler<,,,>).PrettyPrint()}'");
                }

                eventFlowOptions.RegisterServices(sr => {
                    foreach (var handlesCommandType in handlesCommandTypes)
                    {
                        sr.Register(handlesCommandType, t);
                    }
                });
            }

            return(eventFlowOptions);
        }
Example #15
0
        public static IEventFlowOptions AddSubscribers(
            this IEventFlowOptions eventFlowOptions,
            IEnumerable <Type> subscribeSynchronousToTypes)
        {
            foreach (var subscribeSynchronousToType in subscribeSynchronousToTypes)
            {
                var t            = subscribeSynchronousToType;
                var subscribeTos = t
                                   .GetInterfaces()
                                   .Where(i =>
                                          (i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ISubscribeSynchronousTo <, ,>)) ||
                                          i == typeof(ISubscribeSynchronousToAll))
                                   .ToList();
                if (!subscribeTos.Any())
                {
                    throw new ArgumentException($"Type '{t.PrettyPrint()}' is not an '{typeof(ISubscribeSynchronousTo<,,>).PrettyPrint()}'");
                }

                eventFlowOptions.RegisterServices(sr =>
                {
                    foreach (var subscribeTo in subscribeTos)
                    {
                        sr.Register(subscribeTo, t);
                    }
                });
            }

            return(eventFlowOptions);
        }
        protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
        {
            var elasticsearchUrl = Environment.GetEnvironmentVariable("ELASTICSEARCH_URL") ?? "http://localhost:9200";

            // Setup connection settings separateley as by default EventFlow uses SniffingConnectionPool
            // which is not working well with elasticserch hosted in local docker
            var connectionSettings = new ConnectionSettings(new Uri(elasticsearchUrl))
                                     .ThrowExceptions()
                                     .SniffLifeSpan(TimeSpan.FromMinutes(5))
                                     .DisablePing();

            var resolver = eventFlowOptions
                           .RegisterServices(sr => { sr.RegisterType(typeof(ThingyMessageLocator)); })
                           .ConfigureElasticsearch(connectionSettings)
                           .UseElasticsearchReadModel <ElasticsearchThingyReadModel>()
                           .UseElasticsearchReadModel <ElasticsearchThingyMessageReadModel, ThingyMessageLocator>()
                           .AddQueryHandlers(
                typeof(ElasticsearchThingyGetQueryHandler),
                typeof(ElasticsearchThingyGetVersionQueryHandler),
                typeof(ElasticsearchThingyGetMessagesQueryHandler))
                           .CreateResolver();

            PrepareIndexes(resolver);

            return(resolver);
        }
 public static IEventFlowOptions AddQueryHandler <TQueryHandler, TQuery, TResult>(
     this IEventFlowOptions eventFlowOptions)
     where TQueryHandler : class, IQueryHandler <TQuery, TResult>
     where TQuery : IQuery <TResult>
 {
     return(eventFlowOptions.RegisterServices(sr => sr.Register <IQueryHandler <TQuery, TResult>, TQueryHandler>()));
 }
Example #18
0
        public static IEventFlowOptions AddSubscribers(
            this IEventFlowOptions eventFlowOptions,
            IEnumerable <Type> subscribeSynchronousToTypes)
        {
            foreach (var subscribeSynchronousToType in subscribeSynchronousToTypes)
            {
                var t = subscribeSynchronousToType;
                if (t.GetTypeInfo().IsAbstract)
                {
                    continue;
                }

                var subscribeTos = t
                                   .GetTypeInfo()
                                   .GetInterfaces()
                                   .Where(IsSubscriberInterface)
                                   .ToList();
                if (!subscribeTos.Any())
                {
                    throw new ArgumentException($"Type '{t.PrettyPrint()}' is not an '{ISubscribeSynchronousToType.PrettyPrint()}', '{ISubscribeAsynchronousToType.PrettyPrint()}' or '{ISubscribeSynchronousToAllType.PrettyPrint()}'");
                }

                eventFlowOptions.RegisterServices(sr =>
                {
                    foreach (var subscribeTo in subscribeTos)
                    {
                        sr.Register(subscribeTo, t);
                    }
                });
            }

            return(eventFlowOptions);
        }
        public static IEventFlowOptions AddQueryHandlers(
            this IEventFlowOptions eventFlowOptions,
            IEnumerable <Type> queryHandlerTypes)
        {
            foreach (var queryHandlerType in queryHandlerTypes)
            {
                var t = queryHandlerType;
                var queryHandlerInterfaces = t
                                             .GetInterfaces()
                                             .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler <,>))
                                             .ToList();
                if (!queryHandlerInterfaces.Any())
                {
                    throw new ArgumentException(string.Format(
                                                    "Type '{0}' is not a ISubscribeSynchronousTo<TEvent>",
                                                    t.Name));
                }

                eventFlowOptions.RegisterServices(sr =>
                {
                    foreach (var queryHandlerInterface in queryHandlerInterfaces)
                    {
                        sr.Register(queryHandlerInterface, t);
                    }
                });
            }

            return(eventFlowOptions);
        }
Example #20
0
        public void Register(IEventFlowOptions eventFlowOptions)
        {
            // Not sure why this not work
            eventFlowOptions.AddQueryHandlers(typeof(QueryHandlersModule).Assembly);

            eventFlowOptions.RegisterServices(r => { r.Register <BookingQueryHandler, BookingQueryHandler>(); });
        }
Example #21
0
        public static IEventFlowOptions AddQueryHandlers(
            this IEventFlowOptions eventFlowOptions,
            IEnumerable <Type> queryHandlerTypes)
        {
            foreach (var queryHandlerType in queryHandlerTypes)
            {
                var t = queryHandlerType;
                if (t.GetTypeInfo().IsAbstract)
                {
                    continue;
                }
                var queryHandlerInterfaces = t
                                             .GetTypeInfo()
                                             .GetInterfaces()
                                             .Where(IsQueryHandlerInterface)
                                             .ToList();
                if (!queryHandlerInterfaces.Any())
                {
                    throw new ArgumentException($"Type '{t.PrettyPrint()}' is not an '{typeof(IQueryHandler<,>).PrettyPrint()}'");
                }

                eventFlowOptions.RegisterServices(sr =>
                {
                    foreach (var queryHandlerInterface in queryHandlerInterfaces)
                    {
                        sr.Register(queryHandlerInterface, t);
                    }
                });
            }

            return(eventFlowOptions);
        }
 public static IEventFlowOptions UseEventStore(
     this IEventFlowOptions eventFlowOptions,
     Func <IResolverContext, IEventStore> eventStoreResolver,
     Lifetime lifetime = Lifetime.AlwaysUnique)
 {
     return(eventFlowOptions.RegisterServices(f => f.Register(eventStoreResolver, lifetime)));
 }
        public static IEventFlowOptions AddEventUpgraders(
            this IEventFlowOptions eventFlowOptions,
            IEnumerable <Type> eventUpgraderTypes)
        {
            foreach (var eventUpgraderType in eventUpgraderTypes)
            {
                var t = eventUpgraderType;
                if (t.GetTypeInfo().IsAbstract)
                {
                    continue;
                }
                var eventUpgraderForAggregateType = t
                                                    .GetTypeInfo()
                                                    .GetInterfaces()
                                                    .SingleOrDefault(IsEventUpgraderInterface);
                if (eventUpgraderForAggregateType == null)
                {
                    throw new ArgumentException($"Type '{eventUpgraderType.Name}' does not have the '{typeof(IEventUpgrader<,>).PrettyPrint()}' interface");
                }

                eventFlowOptions.RegisterServices(sr => sr.Register(eventUpgraderForAggregateType, t));
            }

            return(eventFlowOptions);
        }
Example #24
0
 public static IEventFlowOptions UseInMemoryReadStoreFor <TReadModel>(
     this IEventFlowOptions eventFlowOptions)
     where TReadModel : class, IReadModel
 {
     return(eventFlowOptions
            .RegisterServices(RegisterInMemoryReadStore <TReadModel>)
            .UseReadStoreFor <IInMemoryReadStore <TReadModel>, TReadModel>());
 }
Example #25
0
 public static IEventFlowOptions AddMetadataProvider <TMetadataProvider>(
     this IEventFlowOptions eventFlowOptions,
     Lifetime lifetime = Lifetime.AlwaysUnique)
     where TMetadataProvider : class, IMetadataProvider
 {
     return(eventFlowOptions
            .RegisterServices(f => f.Register <IMetadataProvider, TMetadataProvider>(lifetime)));
 }
Example #26
0
 public static IEventFlowOptions UseElasticsearchReadModel <TReadModel>(
     this IEventFlowOptions eventFlowOptions)
     where TReadModel : class, IReadModel
 {
     return(eventFlowOptions
            .RegisterServices(RegisterElasticsearchReadStore <TReadModel>)
            .UseReadStoreFor <IElasticsearchReadModelStore <TReadModel>, TReadModel>());
 }
 public static IEventFlowOptions AddEventUpgrader <TAggregate, TIdentity>(
     this IEventFlowOptions eventFlowOptions,
     Func <IResolverContext, IEventUpgrader <TAggregate, TIdentity> > factory)
     where TAggregate : IAggregateRoot <TIdentity>
     where TIdentity : IIdentity
 {
     return(eventFlowOptions.RegisterServices(f => f.Register(factory)));
 }
 public static IEventFlowOptions AddEventUpgrader <TAggregate, TIdentity, TEventUpgrader>(
     this IEventFlowOptions eventFlowOptions)
     where TAggregate : IAggregateRoot <TIdentity>
     where TIdentity : IIdentity
     where TEventUpgrader : class, IEventUpgrader <TAggregate, TIdentity>
 {
     return(eventFlowOptions.RegisterServices(f => f.Register <IEventUpgrader <TAggregate, TIdentity>, TEventUpgrader>()));
 }
 public static IEventFlowOptions UseMssqlReadModel <TReadModel, TReadModelLocator>(
     this IEventFlowOptions eventFlowOptions)
     where TReadModel : class, IReadModel
     where TReadModelLocator : IReadModelLocator
 {
     return(eventFlowOptions
            .RegisterServices(RegisterMssqlReadStore <TReadModel>)
            .UseReadStoreFor <IMssqlReadModelStore <TReadModel>, TReadModel, TReadModelLocator>());
 }
 public static IEventFlowOptions AddMsSqlReadModel(this IEventFlowOptions efo)
 {
     return(efo
            .RegisterServices(sr => sr.Register <IEntryLocator, EntryLocator>())
            .UseMssqlReadModel <CompetitionReadModel>()
            .UseMssqlReadModel <EntryReadModel, IEntryLocator>()
            .AddQueryHandler <GetAllEntriesQueryHandler, GetAllEntriesQuery, EntryReadModel[]>()
            .ConfigureMsSql(MsSqlConfiguration.New.SetConnectionString(ConfigurationManager.ConnectionStrings["ReadModel"].ConnectionString)));
 }
        protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
        {
            var resolver = eventFlowOptions
                .RegisterServices(sr => sr.RegisterType(typeof(ThingyMessageLocator)))
                .UseInMemoryReadStoreFor<InMemoryThingyReadModel>()
                .UseInMemoryReadStoreFor<InMemoryThingyMessageReadModel, ThingyMessageLocator>()
                .AddQueryHandlers(
                    typeof(InMemoryThingyGetQueryHandler),
                    typeof(InMemoryThingyGetVersionQueryHandler),
                    typeof(InMemoryThingyGetMessagesQueryHandler))
                .CreateResolver();

            return resolver;
        }
        protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
        {
            _testDatabase = MsSqlHelpz.CreateDatabase("eventflow");

            var resolver = eventFlowOptions
                .RegisterServices(sr => sr.RegisterType(typeof (ThingyMessageLocator)))
                .ConfigureMsSql(MsSqlConfiguration.New.SetConnectionString(_testDatabase.ConnectionString.Value))
                .UseMssqlReadModel<MsSqlThingyReadModel>()
                .UseMssqlReadModel<MsSqlThingyMessageReadModel, ThingyMessageLocator>()
                .AddQueryHandlers(
                    typeof(MsSqlThingyGetQueryHandler),
                    typeof(MsSqlThingyGetVersionQueryHandler),
                    typeof(MsSqlThingyGetMessagesQueryHandler))
                .CreateResolver();

            var databaseMigrator = resolver.Resolve<IMsSqlDatabaseMigrator>();
            EventFlowEventStoresMsSql.MigrateDatabase(databaseMigrator);
            databaseMigrator.MigrateDatabaseUsingEmbeddedScripts(GetType().Assembly);

            return resolver;
        }