Ejemplo n.º 1
0
        public void Subscribe(IDomainEventSubscriber aSubscriber)
        {
            lock (_lockObj)
            {
                var registeredSubscribers = _subscribers;

                var domainEventType = aSubscriber.SubscribedToEventType();
                List <IDomainEventSubscriber> subscribers;

                if (!registeredSubscribers.TryGetValue(domainEventType, out subscribers))
                {
                    subscribers = new List <IDomainEventSubscriber>();
                    registeredSubscribers.Add(domainEventType, subscribers);
                }

                if (subscribers.Any(ent => ent.SubscribedToEventType().FullName == aSubscriber.SubscribedToEventType().FullName&& ent.GetType().FullName == aSubscriber.GetType().FullName))   //相同的订阅只接收一次。
                {
                    return;
                }

                subscribers.Add(aSubscriber);
            }
        }
        public void Subscribe(IDomainEventSubscriber domainEventSubscriber)
        {
            var eventType = domainEventSubscriber.SubscribedToEventType();

            if (_subscribers.ContainsKey(eventType))
            {
                _subscribers[eventType].Add(domainEventSubscriber);
            }
            else
            {
                _subscribers[eventType] = new List <IDomainEventSubscriber>();
                _subscribers[eventType].Add(domainEventSubscriber);
            }
        }
Ejemplo n.º 3
0
 private static bool IsEventTypeMatch <T>(T domainEvent, IDomainEventSubscriber <IDomainEvent> subscriber) where T : IDomainEvent
 {
     return(domainEvent.GetType() == subscriber.SubscribedToEventType());
 }