Exemple #1
0
        public void ExecuteCommand(ICommandMapping mapping, CommandPayload payload = null)
        {
            bool   hasPayload       = payload != null && payload.HasPayload();
            bool   injectionEnabled = hasPayload && mapping.PayloadInjectionEnabled;
            object command          = null;

            if (injectionEnabled)
            {
                MapPayload(payload);
            }

            if (mapping.Guards.Count == 0 || Guards.Approve(_injector, mapping.Guards))
            {
                Type commandClass = mapping.CommandClass;
                if (mapping.FireOnce && _removeMapping != null)
                {
                    _removeMapping(mapping);
                }
                command = _injector.GetOrCreateNewInstance(commandClass);
                if (mapping.Hooks.Count > 0)
                {
                    _injector.Map(commandClass).ToValue(command);
                    Hooks.Apply(_injector, mapping.Hooks);
                    _injector.Unmap(commandClass);
                }
            }

            if (injectionEnabled)
            {
                UnmapPayload(payload);
            }

            if (command != null && mapping.ExecuteMethod != null)
            {
                if (_onPreprocessCommandExecuting != null)
                {
                    _onPreprocessCommandExecuting.Invoke(command, mapping);
                }

                MethodInfo executeMethod = command.GetType().GetMethod(mapping.ExecuteMethod);
                object     result        = (hasPayload && executeMethod.GetParameters().Length > 0)
                                        ? executeMethod.Invoke(command, payload.Values.ToArray())
                                        : executeMethod.Invoke(command, null);
                if (_handleResult != null)
                {
                    _handleResult.Invoke(result, command, mapping);
                }
            }
        }
        private void ProcessType(Type type)
        {
            object obj = _injector.GetOrCreateNewInstance(type);

            InvokeConfigure(obj, type);
        }