Skip to content

Instantly share code, notes, and snippets.

@scionwest
Created January 17, 2015 20:54
Show Gist options
  • Save scionwest/47bafc0d9094cecffa4c to your computer and use it in GitHub Desktop.
Save scionwest/47bafc0d9094cecffa4c to your computer and use it in GitHub Desktop.
private ConcurrentDictionary<Type, ConcurrentBag<ISubscription>> listeners =
new ConcurrentDictionary<Type, ConcurrentBag<ISubscription>>();
public void Publish<T>(T message) where T : class, IMessage
{
if (!listeners.ContainsKey(typeof(T)))
{
return;
}
foreach (INotificationHandler<T> handler in listeners[typeof(T)])
{
handler.ProcessMessage(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment