Exemplo n.º 1
0
        public void Publish <T>(object source, T message, Action <T> replyTo = null)
        {
            if (source == null || message == null)
            {
                return;
            }
            if (!_subscribers.ContainsKey(typeof(T)))
            {
                return;
            }

            var delegates = _subscribers[typeof(T)];

            if (delegates == null || delegates.Count == 0)
            {
                return;
            }
            var payload = new MessagePayload <T>(message, source, replyTo);

            foreach (var handler in delegates.Select(item => item as Action <MessagePayload <T> >))
            {
                Task.Factory.StartNew(() => handler?.Invoke(payload));
            }
        }