Esempio n. 1
0
 public IDisposable Subscribe <T>(IHandle <T> handler) where T : Message
 {
     Ensure.NotNull(handler, "handler");
     lock (_handlers)
     {
         int[] descendants = MessageHierarchy.DescendantsByType[typeof(T)];
         for (int i = 0; i < descendants.Length; ++i)
         {
             var handlers = _handlers[descendants[i]];
             if (!handlers.Any(x => x.IsSame <T>(handler)))
             {
                 handlers.Add(new MessageHandler <T>(handler, handler.GetType().Name,
                                                     MessageHierarchy.GetMsgTypeId(typeof(T))));
             }
         }
         return(new SubscriptionDisposer(() => { this?.Unsubscribe(handler); return Unit.Default; }));
     }
 }
Esempio n. 2
0
 public bool HasSubscriberFor <T>(bool includeDerived = false) where T : Message
 {
     return(HasSubscriberFor(MessageHierarchy.GetMsgTypeId(typeof(T)), includeDerived));
 }