public static void Main(string[] args)
        {
            var commandBus = new CommandBus();

            var sessionFactory = DbConfig();

            var accountReportView = new AccountReportView(sessionFactory);

            commandBus.RegisterHandlerEvent<AccountCreatedEvent>(accountReportView.Handle);

            commandBus.RegisterHandlerEvent<AccountNameAndBalanceChangedEvent>(accountReportView.Handle);

            commandBus.RegisterHandlerEvent<BalanceDecreasedEvent>(accountReportView.Handle);

            commandBus.RegisterHandlerEvent<BalanceIncreasedEvent>(accountReportView.Handle);

            var r = new RunRabbitMQSubscriber(commandBus);
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);

            RegisterRoutes(RouteTable.Routes);

            var builder = new ContainerBuilder();

            builder.RegisterModule(new NHibernateSessionModule());

            //builder.RegisterModule(new ReportingSessionModule());

            builder.RegisterModule(new QueryModule());

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            var container = builder.Build();

            _container = container;

            QueryModule._container = _container;

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            var rabbitMQPublisher = new RabbitMQPublisher(System.Configuration.ConfigurationManager.AppSettings["CLOUDAMQP_URL"]);

            //Use RabbitMQ
            //var commandBus = new CommandBus(rabbitMQPublisher);

            var commandBus = new CommandBus();

            var sessionFactory = container.Resolve<ISessionFactory>();
            IEventStore eventStore = new NHibernateEventStore(commandBus, sessionFactory);

            //Context
            var transferMoneyContext = new TransferMoneyContext(eventStore);
            var createBankAccountContext = new CreateBankAccountContext(eventStore);
            var changeAccountAndBalanceContext = new ChangeAccountNameAndBalanceContext(eventStore);
            var createCustomerContext = new CreateCustomerContext(eventStore);
            var addCustomerAddressContext = new AddCustomerAddressContext(eventStore);
            var stockNewProductContext = new StockNewProductContext(eventStore);
            var placeOrderContext = new PlaceOrderContext(eventStore);

            //Register Command
            commandBus.RegisterHandlerCommand<OpenAccountCommand>(createBankAccountContext.Handle);
            commandBus.RegisterHandlerCommand<TransferMoneyCommand>(transferMoneyContext.Handle);
            commandBus.RegisterHandlerCommand<ChangeAccountNameAndBalanceCommand>(changeAccountAndBalanceContext.Handle);
            commandBus.RegisterHandlerCommand<CreateCustomerCommand>(createCustomerContext.Handle);
            commandBus.RegisterHandlerCommand<AddCustomerAddressCommand>(addCustomerAddressContext.Handle);
            commandBus.RegisterHandlerCommand<CreateProductCommand>(stockNewProductContext.Handle);
            commandBus.RegisterHandlerCommand<PlaceOrderCommand>(placeOrderContext.Handle);

            //Report View
            var accountReportView = new AccountReportView(sessionFactory);

            //Register Event
            commandBus.RegisterHandlerEvent<AccountCreatedEvent>(accountReportView.Handle);
            commandBus.RegisterHandlerEvent<AccountNameAndBalanceChangedEvent>(accountReportView.Handle);
            commandBus.RegisterHandlerEvent<BalanceDecreasedEvent>(accountReportView.Handle);
            commandBus.RegisterHandlerEvent<BalanceIncreasedEvent>(accountReportView.Handle);

            //Report View
            var customerReportView = new CustomerReportView(container.Resolve<ISessionFactory>());

            //Register Event
            commandBus.RegisterHandlerEvent<CustomerCreatedEvent>(customerReportView.Handle);
            commandBus.RegisterHandlerEvent<CustomerAddressAddedEvent>(customerReportView.Handle);

            var placeOrderView = new PlaceOrderView(container.Resolve<ISessionFactory>());

            commandBus.RegisterHandlerEvent<OrderPlacedEvent>(placeOrderView.Handle);

            var productStockReportView = new ProductStockReportView(container.Resolve<ISessionFactory>());

            commandBus.RegisterHandlerEvent<ProductCreatedEvent>(productStockReportView.Handle);

            //ServiceLocator.Pub = rabbitMQPublisher;
            ServiceLocator.Bus = commandBus;
            //ServiceLocator.Sub = rabbitMQSubsriber;
        }