Example #1
0
        private Configuration()
        {
            /* bus intialisation */
            _bus = new MessageBus();
            //var eventStore = new SqlServerEventStore(_bus);
            //var eventStore = new SqlLiteEventStore(_bus);
            var eventStore = new InMemoryEventStore(_bus, inMemDict );
            var repository = new DomainRepository(eventStore);

            /* Account Domain */
            var commandService = new AccountApplicationService(repository);
            _bus.RegisterHandler<RegisterAccountCommand>(commandService.Handle);
            _bus.RegisterHandler<DebitAccountCommand>(commandService.Handle);
            _bus.RegisterHandler<UnlockAccountCommand>(commandService.Handle);

            var infoProjection = new AccountInfoProjection();
            _bus.RegisterHandler<AccountRegisteredEvent>(infoProjection.Handle);
            _bus.RegisterHandler<AccountLockedEvent>(infoProjection.Handle);
            _bus.RegisterHandler<AccountUnlockedEvent>(infoProjection.Handle);

            var balanceProjection = new AccountBalanceProjection();
            _bus.RegisterHandler<AccountRegisteredEvent>(balanceProjection.Handle);
            _bus.RegisterHandler<AccountDebitedEvent>(balanceProjection.Handle);

            var notification = new NotificationProjection();
            _bus.RegisterHandler<AccountRegisteredEvent>(notification.Handle);
            _bus.RegisterHandler<AccountDebitedEvent>(notification.Handle);
            _bus.RegisterHandler<AccountLockedEvent>(notification.Handle);
            _bus.RegisterHandler<AccountUnlockedEvent>(notification.Handle);
            _bus.RegisterHandler<AccountOverdrawAttemptedEvent>(notification.Handle);

            _AccountReadModel = new AccountReadModelFacade(balanceProjection, infoProjection, notification);

            /*  News Domain*/
            //var newsEventStore = new SqlServerEventStore(_bus);
            //var newsEventStore = new SqlLiteEventStore(_bus);
            var newsEventStore = new InMemoryEventStore(_bus, inMemDict);
            var newsRepository = new DomainRepository(eventStore);

            /* Register command on the News bounded context */
            var newsCommandService = new AccountManager.Models.News.Domain.NewsApplicationService(newsRepository);
            _bus.RegisterHandler<AccountManager.Models.News.Commands.CreateNewsCommand>(newsCommandService.Handle);
            _bus.RegisterHandler<AccountManager.Models.News.Commands.PublishNewsCommand>(newsCommandService.Handle);
            _bus.RegisterHandler<AccountManager.Models.News.Commands.UnpublishNewsCommand>(newsCommandService.Handle);
            _bus.RegisterHandler<AccountManager.Models.News.Commands.UpdateNewsCommand>(newsCommandService.Handle);
            _bus.RegisterHandler<AccountManager.Models.News.Commands.DeleteNewsCommand>(newsCommandService.Handle);

            var _newsProjection = new AccountManager.Models.News.ReadModel.NewsProjection();
            _bus.RegisterHandler<AccountManager.Models.News.Events.NewsCreatedEvent>(_newsProjection.Handle);
            _bus.RegisterHandler<AccountManager.Models.News.Events.NewsPublishedEvent>(_newsProjection.Handle);
            _bus.RegisterHandler<AccountManager.Models.News.Events.NewsUnpublishedEvent>(_newsProjection.Handle);
            _bus.RegisterHandler<AccountManager.Models.News.Events.NewsUpdatedEvent>(_newsProjection.Handle);
            _bus.RegisterHandler<AccountManager.Models.News.Events.NewsDeletedEvent>(_newsProjection.Handle);

            _NewsReadModel = new NewsReadModelFacade(_newsProjection);

            /* rehydrate */
            var events = eventStore.GetAllEventsEver();
            _bus.Publish(events);
        }
 public override void RegisterHandler(MessageBus bus, IRepository repo)
 {
     var svc = new AccountApplicationService(repo);
     bus.RegisterHandler<DebitAccountCommand>(svc.Handle);
 }