/// <summary>
        /// Publish event of type TEvent for handling.
        /// When there are no subscribers for this event NoSubscribers event published
        /// </summary>
        /// <typeparam name="TEvent"></typeparam>
        /// <param name="eventInstance">Event to publish</param>
        /// <param name="sender">sender instance</param>
        public virtual void Publish <TEvent>(TEvent eventInstance, ICanPublish <TEvent> sender)
        {
            if (sender == null)
            {
                // there is no any formal need to have sender in Publish method yet
                // Idea behid this requirement is to mark all classes which can publish events with interface so they can be discoverable
                // (With or without source code)
                throw new ArgumentException("sender could not be null");
            }

            object outValue = null;

            if (_subscribers.TryGetValue(typeof(TEvent), out outValue))
            {
                SubscribersList <TEvent> chain = (SubscribersList <TEvent>)outValue;
                if (chain != null)
                {
                    chain.Execute(eventInstance);
                }
            }
            else
            {
                if (typeof(TEvent) != typeof(NoSubscribers))
                {
                    Publish <NoSubscribers>(countNoSubscribers <TEvent>(eventInstance), this);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Publish event of type TEvent for handling.
 /// When there are no subscribers for this event NoSubscribers event published
 /// </summary>
 /// <typeparam name="TEvent"></typeparam>
 /// <param name="eventInstance">Event to publish</param>
 /// <param name="sender">sender instance</param>
 public static void Publish <TEvent>(TEvent eventInstance, ICanPublish <TEvent> sender)
 {
     Default.Publish(eventInstance, sender);
 }