示例#1
0
        private static void SetUpBus(IWindsorContainer container)
        {
            //TODO: Set up your own connection string in app.config
            var connectionString = ConfigurationManager.AppSettings["AzureConnectionString"];

            // You'll want a logger. There's a ConsoleLogger and a NullLogger if you really don't care. You can roll your
            // own by implementing the ILogger interface if you want to hook it to an existing logging implementation.
            container.Register(Component.For<ILogger>().ImplementedBy<SerilogStaticLogger>().LifestyleSingleton());

            // This is how you tell Cumulus where to find all your message types and handlers.
            var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly());

            container.RegisterCumulus(typeProvider);
            container.Register(Component.For<IBus>().ImplementedBy<Bus>()
                .UsingFactoryMethod<IBus>(() => new BusBuilder()
                    .Configure()
                    .WithConnectionString(connectionString)
                    .WithNames("PingPong.Windsor", Environment.MachineName)
                    .WithTypesFrom(typeProvider)
                    .WithWindsorDefaults(container)
                    .WithJsonSerializer()
                    .WithDeflateCompressor()
                    .Build())
                .LifestyleSingleton()
            );
            Bus bus = (Bus)container.Resolve<IBus>();
            bus.Start().Wait();
        }