Example #1
0
        public void WhenIScheduleAMeeting()
        {
            var scheduleMeetingCommand = new ScheduleMeetingCommand(MEETING_ID, meetingDate, locationId, speakerId, capacity);

            new DomainDatabaseBootStrapper().ReCreateDatabaseSchema();

            var sqliteConnectionString = string.Format("Data Source={0}", DATA_BASE_FILE);

            var domainEventStorage    = new DomainEventStorage <IDomainEvent>(sqliteConnectionString, new BinaryFormatter());
            var eventStoreIdentityMap = new EventStoreIdentityMap <IDomainEvent>();
            var bus = new DirectBus(new MessageRouter());
            var eventStoreUnitOfWork = new EventStoreUnitOfWork <IDomainEvent>(domainEventStorage, eventStoreIdentityMap, bus);
            var repository           = new DomainRepository <IDomainEvent>(eventStoreUnitOfWork, eventStoreIdentityMap);

            new ReportingDatabaseBootStrapper().ReCreateDatabaseSchema();
            reportingRepository = new SQLiteReportingRepository(sqliteConnectionString, new SqlSelectBuilder(), new SqlInsertBuilder(), new SqlUpdateBuilder(), new SqlDeleteBuilder());

            handler = new ScheduleMeetingCommandHandler(repository);

            var messageRouter = new MessageRouter();

            messageRouter.Register <ScheduleMeetingCommand>(command => handler.Handle(command));

            bus.Publish(scheduleMeetingCommand);

            //how do we publish to report, directly or via command handler. Looks like by using transaction handler we go through unit of work whose commit method fires events to BUS
            //so if we have event and then save they get re-ublished and report canpick up
        }
Example #2
0
        public override void Configure(IFunctionsHostBuilder hostBuilder)
        {
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddEnvironmentVariables();
            var configuration = configurationBuilder.Build();

            //set up event store
            hostBuilder.Services.AddSingleton <IEventStoreConnection>(s => new EventStoreConnectionFactory(configuration).Create(s));
            hostBuilder.Services.AddSingleton <IEventStore, Infrastructure.EventStore.EventStore>(s =>
            {
                var con        = s.GetRequiredService <IEventStoreConnection>();
                var eventstore = new Infrastructure.EventStore.EventStore(con);
                return(eventstore);
            });

            var configRoot = new ConfigurationBuilder().AddEnvironmentVariables().Build();

            hostBuilder.Services.AddSingleton(sp => configRoot);
            //ensure one connection for function app
            if (_databaseConnection == null)
            {
                var dbName = configRoot["ReservationsDatabaseName"];
                _databaseConnection = new SqliteConnection("Datasource=./../../../" + dbName);
                _databaseConnection.Open();
            }
            ////repo factory set up
            var repositoryFactory = new SQLRepositoryFactory(_databaseConnection);

            hostBuilder.Services.AddScoped <IRepositoryFactory>(x =>
            {
                return(repositoryFactory);
            });
            //bus wiring
            var bus     = new DirectBus();
            var builder = new Builder(repositoryFactory);

            //register read model denormalizers
            RegisterReadModelDenormalizers(builder);
            //register builder handler with bus
            bus.RegisterEventHandler(builder.Handle);
            //register event store wrapper client
            var serviceProvider  = hostBuilder.Services.BuildServiceProvider();
            var eventStore       = serviceProvider.GetRequiredService <IEventStore>();
            var eventStoreClient = new EventStoreClient(bus, eventStore);

            hostBuilder.Services.AddSingleton <IEventStoreClient>(sp => { return(eventStoreClient); });
            //set up aggregate factories di
            RegisterAggregateFactories(hostBuilder);
            //set up command handlers
            RegisterCommandHandlers(hostBuilder, bus, eventStoreClient);
            //set up query handlers
            RegisterQueryHandlers(hostBuilder, bus);
            //register bus
            hostBuilder.Services.AddSingleton <IBus>(sp => { return(bus); });
        }