コード例 #1
0
 /// <summary>
 /// Create message handler delegate from CommandHandlerAttributeMethod and register to SingleMessageHandlerRegistration.
 /// </summary>
 /// <typeparam name="TCommand">Type of command.</typeparam>
 /// <param name="registration">Message handler registration.</param>
 /// <param name="messageHandlerDelegate">Message handler delegate built from a method marked with [CommandHandler] attribute.</param>
 private static void registerMessageHandlerDelegate <TCommand>(SingleMessageHandlerRegistration registration,
                                                               MessageHandlerDelegate messageHandlerDelegate)
     where TCommand : class
 {
     // Create delegate and register.
     registration.Register <TCommand>(messageHandlerDelegate.Invoke);
 }
コード例 #2
0
        /// <summary>
        /// Register command handler.
        /// </summary>
        /// <typeparam name="TCommand">Type of command to be handled.</typeparam>
        /// <param name="registration">Instance of SingleMessageHandlerRegistration.</param>
        /// <param name="commandHandlerFactory">Factory which will provide an instance of a command handler that handles the specified <typeparamref name="TCommand"/> command.</param>
        /// <param name="yieldExecution">True if execution of synchronous handler should be yielded. Otherwise, false.</param>
        public static void RegisterCommandHandler <TCommand>(this SingleMessageHandlerRegistration registration,
                                                             Func <ICommandHandler <TCommand> > commandHandlerFactory)
            where TCommand : class
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            if (commandHandlerFactory == null)
            {
                throw new ArgumentNullException(nameof(commandHandlerFactory));
            }

            MessageHandlerDelegate messageHandlerDelegate = CommandHandlerDelegateBuilder.FromCommandHandlerFactory(commandHandlerFactory);

            registration.Register <TCommand>(messageHandlerDelegate.Invoke);
        }