Exemplo n.º 1
0
        public static void Configure()
        {
            if (NcqrsEnvironment.IsConfigured)
            {
                return;
            }
            var cfg = new Configuration();

            NcqrsEnvironment.Configure(cfg);
        }
Exemplo n.º 2
0
        public static void BootUp()
        {
            var config = new StructureMapConfiguration(cfg =>
            {
                cfg.For <ICommandService>().Use(InitializeCommandService);
                cfg.For <IEventBus>().Use(InitializeEventBus);
                cfg.For <IEventStore>().Use(InitializeEventStore);
            });

            NcqrsEnvironment.Configure(config);
        }
Exemplo n.º 3
0
        public static void BootUp()
        {
            var config = new StructureMapConfiguration(c =>
            {
                c.For <ICommandService>().Use(BuildCommandService);
                c.For <IEventStore>().Use(BuildEventStore);
                c.For <IEventBus>().Use(BuildEventBus);
            });

            NcqrsEnvironment.Configure(config);
        }
Exemplo n.º 4
0
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;

            NcqrsEnvironment.Configure(new NsbEnvironmentConfiguration(Builder));
            _inProcessEventBus = new InProcessEventBus(false);
            NcqrsEnvironment.SetDefault <IEventBus>(_inProcessEventBus);
            _commandService = new NsbCommandService();
            config.Configurer.RegisterSingleton(typeof(ICommandService), _commandService);
        }
 public void Pop()
 {
     if (NcqrsEnvironment.CurrentConfiguration != this)
     {
         throw new Exception("The current configuration isn't this instance of EnvironmentConfigurationWrapper");
     }
     NcqrsEnvironment.Deconfigure();
     if (_configuration != null)
     {
         NcqrsEnvironment.Configure(_configuration);
     }
 }
 public void Push()
 {
     if (NcqrsEnvironment.CurrentConfiguration != _configuration)
     {
         throw new Exception("This EnvironmentConfigurationWrapper doesn't wrap the current configuration.");
     }
     if (NcqrsEnvironment.IsConfigured)
     {
         NcqrsEnvironment.Deconfigure();
     }
     NcqrsEnvironment.Configure(this);
 }
Exemplo n.º 7
0
        public static void BootUp(InMemoryBufferedBrowsableElementStore buffer)
        {
            var config = new Ncqrs.Config.StructureMap.StructureMapConfiguration(cfg =>
            {
                cfg.For <ICommandService>().Use(InitializeCommandService);
                cfg.For <IEventBus>().Use(x => InitializeEventBus(buffer));
                cfg.For <IEventStore>().Use(InitializeEventStore);
                cfg.For <IKnownCommandsEnumerator>().Use(new AllCommandsInAppDomainEnumerator());
            });

            NcqrsEnvironment.Configure(config);
        }
Exemplo n.º 8
0
        public static void BootUp(IEventHandler <NewNoteAdded> handler, TextChangedHandler textChangedHandler)
        {
            var config = new StructureMapConfiguration(cfg =>
            {
                cfg.For <ICommandService>().Use(InitializeCommandService);
                cfg.For <IEventBus>().Use(InitializeEventBus(handler, textChangedHandler));
                cfg.For <IEventStore>().Use(InitializeEventStore);
                cfg.For <ISnapshotStore>().Use(InitializeSnapshotStore);
                cfg.For <IUnitOfWorkFactory>().Use(() => new SnapshottingUnitOfWorkFactory());
            });

            NcqrsEnvironment.Configure(config);
        }
Exemplo n.º 9
0
 public static void SetupInvoiceFixture(this BaseTestFixture btf)
 {
     if (!initialized)
     {
         NcqrsEnvironment.Configure(new StructureMapConfiguration(
                                        x =>
         {
             x.For <ICommandService>().Use(InitCommandService());
             x.For <ICustomerRepository>().Use(new FakeCustomerRepository());
             x.For <ITaxRepository>().Use(new FakeTaxRepository());
         }
                                        ));
         initialized = true;
     }
 }
Exemplo n.º 10
0
        public void When_get_is_called_but_the_source_did_not_return_an_intance_an_exception_should_be_thrown()
        {
            NcqrsEnvironment.Deconfigure();

            // Arrange
            var repository = new MockRepository();

            NcqrsEnvironment.Configure(repository.StrictMock <IEnvironmentConfiguration>());

            // Act
            Action act = () => NcqrsEnvironment.Get <IBar>();

            // Assert
            act.ShouldThrow <InstanceNotFoundInEnvironmentConfigurationException>();
        }
Exemplo n.º 11
0
        public void Configure(Configure config)
        {
            Builder    = config.Builder;
            Configurer = config.Configurer;

            NcqrsEnvironment.Configure(new NsbEnvironmentConfiguration(Builder));
            var compositeBus = new CompositeEventBus();

            _inProcessEventBus = new InProcessEventBus(false);
            compositeBus.AddBus(new NsbEventBus());
            compositeBus.AddBus(_inProcessEventBus);
            _sendingEventHandler = new MessageSendingEventHandler();
            _inProcessEventBus.RegisterHandler(_sendingEventHandler);
            NcqrsEnvironment.SetDefault(compositeBus);
            _messageService = new MessageService();
            config.Configurer.RegisterSingleton(typeof(IMessageService), _messageService);
        }
Exemplo n.º 12
0
        public void When_get_is_called_the_call_should_be_redirected_to_the_configuration()
        {
            NcqrsEnvironment.Deconfigure();

            // Arrange
            IFoo outParameter;
            var  configuration = MockRepository.GenerateStub <IEnvironmentConfiguration>();

            configuration.Stub(x => x.TryGet(out outParameter)).Return(true).OutRef(new Foo());
            NcqrsEnvironment.Configure(configuration);

            // Act
            NcqrsEnvironment.Get <IFoo>();

            // Assert
            configuration.AssertWasCalled(x => x.TryGet(out outParameter));
        }
Exemplo n.º 13
0
        public void When_get_is_called_the_call_should_return_what_the_environment_configuration_returned()
        {
            NcqrsEnvironment.Deconfigure();

            // Arrange
            IFoo outParameter;
            IFoo returnValue = new Foo();

            var configuration = MockRepository.GenerateStub <IEnvironmentConfiguration>();

            configuration.Stub(x => x.TryGet(out outParameter)).Return(true).OutRef(returnValue);
            NcqrsEnvironment.Configure(configuration);

            // Act
            var result = NcqrsEnvironment.Get <IFoo>();

            // Assert
            result.Should().Be(returnValue);
        }
Exemplo n.º 14
0
        public void Configured_instance_should_over_rule_default()
        {
            var    defaultClock    = new DateTimeBasedClock();
            var    configuredClock = MockRepository.GenerateMock <IClock>();
            IClock ingore;

            var configuration = MockRepository.GenerateMock <IEnvironmentConfiguration>();

            configuration.Stub((m) => m.TryGet(out ingore)).IgnoreArguments().OutRef(configuredClock).Return(true);

            NcqrsEnvironment.SetDefault <IClock>(defaultClock);
            NcqrsEnvironment.Configure(configuration);

            var result = NcqrsEnvironment.Get <IClock>();

            Assert.AreSame(configuredClock, result);
            Assert.AreNotSame(defaultClock, result);

            NcqrsEnvironment.Deconfigure();
        }
Exemplo n.º 15
0
        private static void ConfigureNcqrsEnvironment(InMemoryBufferedBrowsableElementStore buffer)
        {
            var eventStoreConnectionString = ConfigurationManager.ConnectionStrings["MyNotes Event Store"].ConnectionString;
            var eventStore = new MsSqlServerEventStore(eventStoreConnectionString);

            Assembly domainAssembly = Assembly.LoadFrom("MyNotes.Domain.dll");

            IWindsorContainer container = new WindsorContainer();

            container.AddFacility("ncqrs.ds", new DynamicSnapshotFacility(domainAssembly));
            container.Register(
                Component.For <ISnapshottingPolicy>().ImplementedBy <SimpleSnapshottingPolicy>(),
                Component.For <ICommandService>().Instance(InitializeCommandService()),
                Component.For <IEventBus>().Instance(InitializeEventBus(buffer)),
                Component.For <IEventStore>().Forward <ISnapshotStore>().Instance(eventStore),
                Component.For <IKnownCommandsEnumerator>().Instance(new AllCommandsInAppDomainEnumerator()),
                Component.For <Note>().AsSnapshotable());

            WindsorConfiguration config = new WindsorConfiguration(container);

            NcqrsEnvironment.Configure(config);
        }
Exemplo n.º 16
0
        public override void AfterStart()
        {
            base.AfterStart();

            NcqrsEnvironment.Configure(new RsbEnvironmentConfiguration(container));
        }