Esempio n. 1
0
        private void RegisterInfrastructure(IUnityContainer container)
        {
            var connectionStringSettings = ConfigurationManager.ConnectionStrings["MKWeb"];

            container.RegisterInstance(Common.Module.MkConnectionString, connectionStringSettings);

            Database.SetInitializer <EventStoreDbContext>(null);

            container.RegisterInstance <ITextSerializer>(new JsonTextSerializer());
            container.RegisterInstance <IMetadataProvider>(new StandardMetadataProvider());

            // Repository
            container.RegisterType <EventStoreDbContext>(new TransientLifetimeManager(),
                                                         new InjectionConstructor(connectionStringSettings.ConnectionString));
            container.RegisterType(typeof(IEventSourcedRepository <>), typeof(SqlEventSourcedRepository <>),
                                   new ContainerControlledLifetimeManager());

            // Command bus
            var commandBus = new AsynchronousMemoryCommandBus(container.Resolve <ITextSerializer>());

            container.RegisterInstance <ICommandBus>(commandBus);
            container.RegisterInstance <ICommandHandlerRegistry>(commandBus);

            // Event bus
            var eventBus = new AsynchronousMemoryEventBus(container.Resolve <ITextSerializer>());

            container.RegisterInstance <IEventBus>(eventBus);
            container.RegisterInstance <IEventHandlerRegistry>(eventBus);
        }
        public async void when_no_exception_then_invoke_once()
        {
            var counthandler = new FakeHandler();
            var sut          = new AsynchronousMemoryCommandBus(new JsonTextSerializer(), counthandler);

            await sut.SendAwaitable(new RegisterAccount());

            Assert.That(counthandler.Invocation, Is.EqualTo(1));
        }
        public async void when_exception_then_invoke_retry()
        {
            var counthandler = new FakeHandler(true);
            var sut          = new AsynchronousMemoryCommandBus(new JsonTextSerializer(), counthandler);

            var envelope = new Envelope <ICommand>(new RegisterAccount());

            envelope.RetryCount = 3;
            await sut.SendAwaitable(envelope);

            Assert.That(counthandler.Invocation, Is.EqualTo(3));
        }