/// <summary>
 /// Create message handler delegate from EventHandlerAttributeMethod and register to MultiMessageHandlerRegistration.
 /// </summary>
 /// <typeparam name="TEvent">Type of event.</typeparam>
 /// <param name="registration">Message handler registration.</param>
 /// <param name="messageHandlerDelegate">Message handler delegate built from a method marked with [EventHandler] attribute.</param>
 private static void RegisterMessageHandlerDelegate <TEvent>(MultiMessageHandlerRegistration registration,
                                                             MessageHandlerDelegate messageHandlerDelegate)
     where TEvent : class
 {
     // Create delegate and register.
     registration.Register <TEvent>(messageHandlerDelegate.Invoke);
 }
        /// <summary>
        /// Register event async handler as subscriber.
        /// </summary>
        /// <typeparam name="TEvent">Type of event to subscribe to.</typeparam>
        /// <param name="registration">Instance of MultiMessageHandlerRegistration.</param>
        /// <param name="eventAsyncHandlerFactory">Factory which will create an instance of an event handler that handles the specified <typeparamref name="TEvent"/> event.</param>
        public static void RegisterEventHandler <TEvent>(this MultiMessageHandlerRegistration registration,
                                                         Func <IEventAsyncHandler <TEvent> > eventAsyncHandlerFactory)
            where TEvent : class
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

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

            MessageHandlerDelegate messageHandlerDelegate = EventHandlerDelegateBuilder.FromEventHandlerFactory(eventAsyncHandlerFactory);

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