void IHandleCommands <TCommand> .Handle(ICommandHandlingContext <TCommand> handlingContext)
        {
            var command = handlingContext.Command;

            var domainRepository = _domainRepositoryResolver.GetRepository(null);

            try
            {
                var aggregateRoot = domainRepository.GetById <TAggregateRoot>(command.AggregateRootId);

                ValidateTheCommand(handlingContext, command, aggregateRoot);

                Handle(command, aggregateRoot);

                if (aggregateRoot != null)
                {
                    domainRepository.Save(aggregateRoot);
                }
            }
            finally
            {
                if (domainRepository != null)
                {
                    _domainRepositoryResolver.Release(domainRepository);
                }
            }
        }
        public async Task <CommandResult> HandleAsync(ICommandHandlingContext <CreateInventoryMasterCommand> context)
        {
            var db      = context.GetMe <IDomainStore>();
            var command = context.Command;

            var master = new InventoryMaster
            {
                GeneralNomenclature = command.GeneralNomenclature,
                IsGArmy             = command.IsGArmy,
                LIN          = command.LIN,
                Status       = command.Status,
                TrackingType = command.TrackingType
            };

            await db.SaveAsync(master);

            //want to track created event
            var usernameProvider = context.GetMe <IUsernameProvider>();

            context.PublishEvent(new InventoryMasterCreatedEvent(
                                     master.AggregateRootId,
                                     command.LIN,
                                     command.GeneralNomenclature,
                                     command.IsGArmy,
                                     command.TrackingType,
                                     usernameProvider.GetUsername()));

            return(CommandResult.Success());
        }
            private void ExecuteTheCommandHandler(ICommandHandlingContext <ICommand> handlingContext)
            {
                var handleMethod   = GetTheHandleMethod();
                var commandHandler = CreateTheCommandHandler();

                handleMethod.Invoke(commandHandler, new object[] { handlingContext });
            }
Example #4
0
        Task IHandleCommands <TCommand> .Handle(ICommandHandlingContext <TCommand> handlingContext)
        {
            context = handlingContext;

            Validate(handlingContext.Command);

            return(Handle(handlingContext.Command));
        }
        public async Task <CommandResult> HandleAsync(ICommandHandlingContext <DeleteInventoryMasterCommand> context)
        {
            var db      = context.GetMe <IDomainStore>();
            var command = context.Command;

            await db.DeleteAsync <InventoryMaster>(command.AggregateRootId);

            return(CommandResult.Success());
        }
        void IHandleCommands <TCommand> .Handle(ICommandHandlingContext <TCommand> handlingContext)
        {
            var command = handlingContext.Command;

            ValidateTheCommand(handlingContext, command);

            var domainRepository = GetTheDomainRepository();
            var aggregateRoot    = domainRepository.GetById <TAggregateRoot>(command.AggregateRootId);

            Handle(command, aggregateRoot);
            domainRepository.Save(aggregateRoot);
        }
Example #7
0
            private void ExecuteTheCommandHandler(ICommandHandlingContext <ICommand> handlingContext)
            {
                var handleMethod   = GetTheHandleMethod();
                var commandHandler = CreateTheCommandHandler();

                try
                {
                    handleMethod.Invoke(commandHandler, new object[] { handlingContext });
                }
                catch (TargetInvocationException ex)
                {
                    throw new Exception(
                              string.Format("Command handler '{0}' for '{1}' failed. Inspect inner exception.", commandHandler.GetType().Name, handlingContext.Command.GetType().Name),
                              ex.InnerException);
                }
            }
Example #8
0
        public Task HandleAsync(
            ICommandHandlingContext <LogInUser> context,
            CancellationToken cancellationToken = default)
        {
            ExecutionContext.CurrentUser = new User
            {
                Name       = context.Command.Name,
                LoggedInAt = DateTime.Now
            };

            _eventDispatcher.DispatchAsync(new UserWasLoggedIn(
                                               ExecutionContext.CurrentUser.Name,
                                               ExecutionContext.CurrentUser.LoggedInAt),
                                           cancellationToken);

            return(Task.CompletedTask);
        }
            private async Task ExecuteTheCommandHandler(IUnityContainer container, ICommandHandlingContext <ICommand> handlingContext)
            {
                var handleMethod   = GetTheHandleMethod();
                var commandHandler = container.Resolve(commandHandlerType);

                try
                {
                    await(Task) handleMethod.Invoke(commandHandler, new object[] { handlingContext });
                    return;
                }
                catch (TargetInvocationException ex)
                {
                    throw new CommandHandlerInvocationException(
                              string.Format("Command handler '{0}' for '{1}' failed. Inspect inner exception.", commandHandler.GetType().Name, handlingContext.Command.GetType().Name),
                              ex.InnerException)
                          {
                              HandlingContext = handlingContext
                          };
                }
            }
Example #10
0
        public async Task <CommandResult> HandleAsync(ICommandHandlingContext <UpdateInventoryMasterCommand> context)
        {
            var db               = context.GetMe <IDomainStore>();
            var command          = context.Command;
            var usernameProvider = context.GetMe <IUsernameProvider>();

            var master = await db.GetExistingByIdAsync <InventoryMaster>(command.AggregateRootId);

            //i want to see when the lin changes

            if (master.LIN != command.LIN)
            {
                context.PublishEvent(new LinChangedEvent(
                                         master.AggregateRootId,
                                         command.LIN,
                                         usernameProvider.GetUsername()));
            }

            master.LIN = command.LIN;
            master.GeneralNomenclature = command.GeneralNomenclature;
            master.IsGArmy             = command.IsGArmy;
            master.TrackingType        = command.TrackingType;
            master.Status = command.Status;

            await db.SaveAsync(master);

            //want to track created event

            context.PublishEvent(new InventoryMasterUpdatedEvent(
                                     master.AggregateRootId,
                                     command.LIN,
                                     command.GeneralNomenclature,
                                     command.IsGArmy,
                                     command.TrackingType,
                                     usernameProvider.GetUsername()));

            return(CommandResult.Success());
        }
Example #11
0
        void IHandleCommands <TCommand> .Handle(ICommandHandlingContext <TCommand> handlingContext)
        {
            context = handlingContext;

            Handle(handlingContext.Command);
        }
 public Task HandleAsync(ICommandHandlingContext <SomeBuggyCommand> context, CancellationToken cancellationToken = default)
 {
     throw new InvalidOperationException(context.Command.ExceptionText);
 }
 public Task <string> HandleAsync(
     ICommandHandlingContext <SomeCommandWithResult> context,
     CancellationToken cancellationToken = default)
 {
     return(Task.FromResult(context.Command.SomeProperty));
 }
 public Task HandleAsync(
     ICommandHandlingContext <SomeCommand> context,
     CancellationToken cancellationToken = default)
 {
     return(Task.CompletedTask);
 }
 public void Handle(ICommandHandlingContext <MyTest2Command> handlingContext)
 {
     handlingContext.Return(handlingContext.Command.ReturnValue);
 }
Example #16
0
 public Task Invoke(ICommandHandlingContext context, object next)
 {
     return(Task.CompletedTask);
 }
Example #17
0
 public void Invoke(ICommandHandlingContext context, IPipe <ICommandHandlingContext> next)
 {
 }
 public void Handle(ICommandHandlingContext <RegisterUserCommand> handlingContext, Exception exception)
 {
 }
Example #19
0
 public Task <Either <string, ValidationState> > HandleAsync(
     ICommandHandlingContext <TestCommandWithEitherResult> context,
     CancellationToken cancellationToken = default)
 {
     return(Task.FromResult(new Either <string, ValidationState>("Some result")));
 }
Example #20
0
 public Task <string> HandleAsync(
     ICommandHandlingContext <TestCommand> context,
     CancellationToken cancellationToken = default)
 {
     return(Task.FromResult("Some result"));
 }
 public async Task <Notification> ValidateAsync(ICommandHandlingContext <UpdateInventoryMasterCommand> context)
 {
     return(await EnsureUniqueLIN(context.Command.AggregateRootId, context.Command.LIN, context.GetMe <IQueryBus>()));
 }
 private void ValidateTheCommand(ICommandHandlingContext <TCommand> handlingContext, TCommand command, TAggregateRoot aggregateRoot)
 {
     ValidationResult = ValidateCommand(command, aggregateRoot);
     handlingContext.Return(ValidationResult);
 }
 private void ValidateTheCommand(ICommandHandlingContext <TCommand> handlingContext, TCommand command)
 {
     ValidationResult = ValidateCommand(command);
     handlingContext.Return(ValidationResult);
 }