public void PicksUpRandomPrivateHandlerWhenDoingAutoRegistration()
        {
            var container = new WindsorContainer();

            container.AutoRegisterHandlersFromAssemblyOf <TestAssemblyScanning>();

            var secretHandlers = container.ResolveAll <IHandleMessages <Secret> >();

            Assert.That(secretHandlers.Length, Is.EqualTo(1));
            Assert.That(secretHandlers.Single(), Is.TypeOf <SecretHandler>());
        }
Exemple #2
0
        static void Main(string[] args)
        {
            using (var windsorContainer = new WindsorContainer())
            {
                CoreDddNhibernateInstaller.SetUnitOfWorkLifeStyle(x => x.PerRebusMessage());

                windsorContainer.Install(
                    FromAssembly.Containing <CoreDddInstaller>(),
                    FromAssembly.Containing <CoreDddNhibernateInstaller>()
                    );

                windsorContainer.Register(
                    Component.For <INhibernateConfigurator>()
                    .ImplementedBy <CoreDddSharedNhibernateConfigurator>()
                    .LifeStyle.Singleton
                    );

                windsorContainer.Register(
                    Component.For <IInternationalMaritimeOrganizationVerifier>()
                    .ImplementedBy <InternationalMaritimeOrganizationVerifier>()
                    .LifeStyle.Transient
                    );

                // register command handlers
                windsorContainer.Register(
                    Classes
                    .FromAssemblyContaining <CreateNewShipCommandHandler>()
                    .BasedOn(typeof(ICommandHandler <>))
                    .WithService.FirstInterface()
                    .Configure(x => x.LifestyleTransient()));

                // register domain event handlers
                windsorContainer.Register(
                    Classes
                    .FromAssemblyContaining <ShipCreatedDomainEventHandler>()
                    .BasedOn(typeof(IDomainEventHandler <>))
                    .WithService.FirstInterface()
                    .Configure(x => x.LifestyleTransient()));

                windsorContainer.AutoRegisterHandlersFromAssemblyOf <VerifyImoNumberShipCreatedDomainEventMessageHandler>();

                DomainEvents.Initialize(windsorContainer.Resolve <IDomainEventHandlerFactory>());

                RebusUnitOfWork.Initialize(
                    unitOfWorkFactory: windsorContainer.Resolve <IUnitOfWorkFactory>(),
                    isolationLevel: System.Data.IsolationLevel.ReadCommitted
                    );

                var rebusConfigurer = Configure.With(new CastleWindsorContainerAdapter(windsorContainer))
                                      .Transport(x => x.UseRabbitMq("amqp://*****:*****@localhost", "ServiceApp"))
                                      .Options(o =>
                {
                    o.EnableUnitOfWork(
                        RebusUnitOfWork.Create,
                        RebusUnitOfWork.Commit,
                        RebusUnitOfWork.Rollback,
                        RebusUnitOfWork.Cleanup
                        );
                });
                using (var bus = rebusConfigurer.Start())
                {
                    bus.Subscribe <ShipCreatedDomainEventMessage>().Wait();

                    Console.WriteLine("Press enter to quit");
                    Console.ReadLine();
                }
            }
        }