public void Start(IAppBuilder app)
        {
            WarmupPlugins();


            _log.Debug("Starting ...");
            try
            {
                _compositionRoot.Build(registrar =>
                {
                    LetPluginsRegisterServices(registrar);

                    registrar.RegisterService <IMessageBus>(x =>
                    {
                        var queue = x.Resolve <IMessageQueueProvider>().Open("Messaging");
                        var bus   = new SingleInstanceMessageBus(queue);
                        return(bus);
                    }, Lifetime.Singleton);
                    registrar.RegisterConcrete <ScopedQueryBus>();
                    registrar.RegisterService(CreateMessageInvoker, Lifetime.Scoped);

                    registrar.RegisterService(x => CreateQueueListener(x, "Messaging", "Messaging"), Lifetime.Singleton);
                    registrar.RegisterService(x => CreateQueueListener(x, "Reports", "Messaging"), Lifetime.Singleton);
                    registrar.RegisterService(x => CreateQueueListener(x, "Feedback", "Messaging"), Lifetime.Singleton);
                    registrar.RegisterInstance <IMessageQueueProvider>(_queueProvider);

                    // let us guard it since it runs events in the background.
                    //var service = registrar.Registrations.First(x => x.Implements(typeof(IMessageBus)));
                    //service.AddService(typeof(IApplicationService));
                }, Startup.ConfigurationStore);

                var listeners = Container.ResolveAll <QueueListener>().ToArray();
                listeners
                .ForEach(x => x
                         .RunAsync(_shutdownToken.Token)
                         .ContinueWith(OnStopped)
                         );

                BuildServices();
                _appManager.Start();
                _backgroundJobManager.Start();
                _log.Debug("...started");
            }
            catch (Exception exception)
            {
                _log.Error("Failed to start.", exception);
                throw;
            }
        }
        public void Configure(ConfigurationContext context)
        {
            var assembly = typeof(IAccountService).Assembly;

            context.Services.RegisterMessageHandlers(assembly);

            assembly = typeof(SqlServerTools).Assembly;
            context.Services.RegisterMessageHandlers(assembly);

            context.Services.AddSingleton <IMessageQueueProvider>(CreateQueueProvider(context));
            context.Services.AddSingleton <IMessageBus>(x =>
            {
                var queue = x.GetService <IMessageQueueProvider>().Open("Messaging");
                var bus   = new SingleInstanceMessageBus(queue);
                return(bus);
            });
            context.Services.AddScoped <IQueryBus, ScopedQueryBus>();
            context.Services.AddScoped(CreateMessageInvoker);

            _messagingQueueListener = ConfigureQueueListener(context, "Messaging", "Messaging");
        }