public virtual CommandContext BuildContextTree(CommandContext currentContext, IEnumerable <ICommandRegistration> commandRegistrations)
        {
            if (currentContext.Parameters.Count == 0)
            {
                return(currentContext);
            }

            var childCommandName = currentContext.Parameters.First();
            var children         = CommandRegistrationHelper.GetChildren(currentContext.CommandRegistration, commandRegistrations);
            var childCommand     = GetCommandRegistration(currentContext.Actor, childCommandName, children);

            if (childCommand == null)
            {
                return(currentContext);
            }

            var scope        = childCommand.Component.LifetimeScope.BeginLifetimeScope();
            var childContext = new CommandContext(childCommand, scope, currentContext)
            {
                CommandRegistration = childCommand
            };

            currentContext.ChildContext = childContext;

            return(BuildContextTree(childContext, commandRegistrations));
        }
예제 #2
0
        public virtual CommandContext BuildContextTree(CommandContext currentContext, IReadOnlyCollection <ICommandRegistration> commandRegistrations)
        {
            if (currentContext == null)
            {
                throw new ArgumentNullException(nameof(currentContext));
            }

            if (currentContext.Parameters.Count == 0)
            {
                return(currentContext);
            }

            var childCommandName = currentContext.Parameters.First();

            if (currentContext.CommandRegistration == null)
            {
                return(currentContext);
            }

            var children     = CommandRegistrationHelper.GetChildren(currentContext.CommandRegistration, commandRegistrations);
            var childCommand = GetCommandRegistration(currentContext.Actor, childCommandName, children);

            if (childCommand == null)
            {
                return(currentContext);
            }

            var scope        = childCommand.Component.LifetimeScope.BeginLifetimeScopeEx();
            var childContext = new CommandContext(childCommand, scope, currentContext)
            {
                CommandRegistration = childCommand
            };

            currentContext.ChildContext = childContext;

            return(BuildContextTree(childContext, commandRegistrations));
        }