public void RemoveHandler <TMsg>(IHandler <TMsg> handlerToRemove) where TMsg : class, IMessage { NarrowingHandler <IMessage, TMsg> narrowingHandler = _handlers.OfType <NarrowingHandler <IMessage, TMsg> >() .SingleOrDefault(x => x.Handler == handlerToRemove); if (narrowingHandler != null) { _handlers.Remove((IHandler <T>)narrowingHandler); } }
public void Subscribe <T>(string topic, IHandler <T> handler) where T : class, IMessage { var imessageshandler = new NarrowingHandler <IMessage, T>(handler); Multiplexer <IMessage> existingHandler; if (_subscriptions.TryGetValue(topic, out existingHandler)) { var clone = existingHandler.Clone(); clone.AddHandler(imessageshandler); _subscriptions[topic] = clone; } else { var handlers = new Multiplexer <IMessage>(new[] { imessageshandler }); _subscriptions.Add(topic, handlers); } }