Beispiel #1
0
        public void Unsubscribe <TMessage>(Action <TMessage> action)
        {
            var messageType = typeof(TMessage);

            if (!_subscribers.ContainsKey(messageType))
            {
                return;
            }

            var comparator = new SubscriptionHandler <TMessage>(action);
            var handler    = _subscribers[messageType].FirstOrDefault(h => h.Equals(comparator));

            if (handler != null)
            {
                _subscribers[messageType].Remove(handler);
            }
        }
Beispiel #2
0
        public void Subscribe <TMessage>(Action <TMessage> action)
        {
            var messageType = typeof(TMessage);
            var handler     = new SubscriptionHandler <TMessage>(action);

            if (!_subscribers.ContainsKey(messageType))
            {
                _subscribers.Add(messageType, new List <IHandleSubscriptions>());
            }

            if (_subscribers[messageType].Contains(handler))
            {
                return;
            }

            _subscribers[messageType].Add(handler);
        }
Beispiel #3
0
 private bool Equals(SubscriptionHandler <T> other)
 {
     return(Equals(Action, other.Action));
 }