Exemple #1
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); });
        }
Exemple #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);

            //set up external service bus event publisher
            var externalBusEventPublisher = hostBuilder.Services.BuildServiceProvider().GetService <IPublisher>();

            if (externalBusEventPublisher == null)
            {
                string serviceBusConnectionString = configRoot["HOTEL_MANAGEMENT_SERVICEBUS"];
                string topicName = configRoot["INVENTORY_EVENTS_TOPIC_NAME"];
                externalBusEventPublisher = new ServiceBusPublisher(serviceBusConnectionString, topicName);
                hostBuilder.Services.AddSingleton(externalBusEventPublisher);
            }
            //set up repositories
            RegisterRepositories(hostBuilder, configRoot);
            ////repo factory set up
            var repositoryFactory = new RepositoryFactory(new DependencyResolver(hostBuilder.Services));

            hostBuilder.Services.AddScoped <IRepositoryFactory>(x =>
            {
                return(repositoryFactory);
            });
            //bus wiring
            var bus     = new Bus();
            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, externalBusEventPublisher);

            hostBuilder.Services.AddSingleton <IEventStoreClient>(sp => { return(eventStoreClient); });
            //register bus
            hostBuilder.Services.AddSingleton <IBus>(sp => { return(bus); });
        }