Ejemplo n.º 1
0
        private void registerCommandHandlerMethod <TAttributed, TCommand>(Func <TAttributed> attributedObjectFactory, CommandHandlerAttributeMethod commandHandlerMethod)
            where TAttributed : class
            where TCommand : class, ICommand
        {
            Type commandType = typeof(TCommand);

            CommandHandlerDelegate handleCommandDelegate;

            if (_commandHandlerDelegatesByCommandType.TryGetValue(commandType, out handleCommandDelegate))
            {
                throw new InvalidOperationException($"Duplicate command handler registered for {commandType.Name}.");
            }

            CommandHandlerDelegate newHandleCommandDelegate = commandHandlerMethod.CreateDelegate <TAttributed, TCommand>(attributedObjectFactory);

            _commandHandlerDelegatesByCommandType.Add(commandType, newHandleCommandDelegate);
        }