Example #1
0
        private void Add(string messageName, Type handlerType)
        {
            if (!this.Exists(messageName))
            {
                this.map.Add(messageName, new List <SubscriptionDetails>());
            }

            if (this.map[messageName].Any(s => s.HandlerType == handlerType))
            {
                throw new ArgumentException(
                          $"handler {handlerType.Name} already registered for '{messageName}'", nameof(handlerType));
            }

            this.map[messageName].Add(SubscriptionDetails.Create(handlerType));
        }
Example #2
0
        private void Remove(string messageName, SubscriptionDetails subscription)
        {
            if (subscription != null)
            {
                this.map[messageName].Remove(subscription);
                if (!this.map[messageName].Any())
                {
                    this.map.Remove(messageName);
                    var messageType = this.messageTypes.SingleOrDefault(e => e.Name == messageName);
                    if (messageType != null)
                    {
                        this.messageTypes.Remove(messageType);
                    }

                    this.RaiseOnRemoved(messageName);
                }
            }
        }