예제 #1
0
        public override void Load()
        {
            string sqlconnectionStrings = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            this.Bind <IRouteMessages>().To <MessageRouter>().InSingletonScope();
            this.Bind <ICommandBus>().To <FakeBus>().InRequestScope();
            this.Bind <IEventBus>().To <FakeBus>().InRequestScope();
            this.Bind <IFormatter>().To <BinaryFormatter>().InRequestScope();
            //this.Bind<IEventStore>().To<SqlServerEventStore>().InRequestScope().WithConstructorArgument(
            //    "sqlConnectionString", sqlconnectionStrings);
            this.Bind <IEventStore>().To <SqlServerEventStore>();
            this.Bind(typeof(IDomainRepository <>)).To(typeof(DomainRepository <>)).InRequestScope();

            var commands = HandlerHelper.GetCommands();
            var handlers = HandlerHelper.GetHandlers();
            var events   = HandlerHelper.GetEvents();

            foreach (var command in commands)
            {
                IList <Type> commandHandlerTypes;
                if (!handlers.TryGetValue(command, out commandHandlerTypes))
                {
                    throw new Exception(string.Format("No command handlers found for command '{0}'", command.FullName));
                }

                foreach (var commandHandler in commandHandlerTypes)
                {
                    this.Bind(typeof(IHandle <>).MakeGenericType(command)).To(commandHandler);
                }
            }

            foreach (var @event in events)
            {
                IList <Type> commandHandlerTypes;
                if (!handlers.TryGetValue(@event, out commandHandlerTypes))
                {
                    throw new Exception(string.Format("No event handlers found for event '{0}'", @event.FullName));
                }

                foreach (var commandHandler in commandHandlerTypes)
                {
                    this.Bind(typeof(IHandle <>).MakeGenericType(@event)).To(commandHandler);
                }
            }

            //below first string is constructor parameter name and second string is constructor parameter value
            //this.Bind<IReportingRepository>().To<ReportingRepository>().InRequestScope().WithConstructorArgument(
            //    "connectionString", new SqlConnection());
            this.Bind <IReportingUnitOfWork>().To <ReportingUnitOfWork>();
            this.Bind <IReportingRepository>().To <ReportingRepository>().WithConstructorArgument("IReportingUnitOfWork", new ReportingUnitOfWork());
        }
예제 #2
0
        public void BootStrapTheBus()
        {
            //var router = MvcApplication.InventoryKernal.Get<IRouteMessages>();

            _createActionMethod = GetType().GetMethod("CreateAction");
            _registerMethod     = _router.GetType().GetMethod("RegisterHandler");

            var commands = HandlerHelper.GetCommands();
            var handlers = HandlerHelper.GetHandlers();
            var events   = HandlerHelper.GetEvents();

            foreach (var command in commands)
            {
                IList <Type> commandHandlerTypes;
                if (!handlers.TryGetValue(command, out commandHandlerTypes))
                {
                    throw new Exception(string.Format("No command handlers found for command '{0}'", command.FullName));
                }

                foreach (var commandHandler in commandHandlerTypes)
                {
                    var injectedHandler = GetCorrectlyInjectedHandler(commandHandler);
                    var action          = CreateTheProperAction(command, injectedHandler);
                    RegisterTheCreatedActionWithTheMessageRouter(_router, command, action);
                }
            }

            foreach (var @event in events)
            {
                IList <Type> commandHandlerTypes;
                if (!handlers.TryGetValue(@event, out commandHandlerTypes))
                {
                    throw new Exception(string.Format("No event handlers found for event '{0}'", @event.FullName));
                }

                foreach (var commandHandler in commandHandlerTypes)
                {
                    var injectedHandler = GetCorrectlyInjectedHandler(commandHandler);
                    var action          = CreateTheProperAction(@event, injectedHandler);
                    RegisterTheCreatedActionWithTheMessageRouter(_router, @event, action);
                }
            }
        }