Пример #1
0
 /// <summary>
 /// 订阅领域事件
 /// </summary>
 /// <param name="subscriber"></param>
 public void Subscribe(IDomainEventSubscriber <IDomainEvent> subscriber)
 {
     if (!this.publishing)
     {
         this.Subscribers.Add(subscriber);
     }
 }
Пример #2
0
        /// <summary>
        /// <see cref="IDomainEventPublisher.Unsubscribe{T}(IDomainEventSubscriber{T})"/>
        /// </summary>
        public void Unsubscribe <T>(IDomainEventSubscriber <T> subscriber) where T : IDomainEvent
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }

            _subscribers.Remove(subscriber);
        }
Пример #3
0
        protected virtual void OnDistributeExceptionEvent(IDomainEventSubscriber subscriber, IDomainEvent domainEvent, Exception exception)
        {
            var handler = DistributeExceptionEvent;

            if (handler != null)
            {
                handler(subscriber, domainEvent, exception);
            }
        }
Пример #4
0
 public CreateWorkItem(IEnumerable <IHandleDomainEvent <WorkItemCreatedEvent, WorkItemId> > workItemCreatedHandlers,
                       IDomainEventSubscriber eventSubscriber, IWriteRepository <WorkItem, WorkItemId> writeRepository,
                       IUnitOfWork unitOfWork, IBus bus)
 {
     this.workItemCreatedHandlers = workItemCreatedHandlers;
     this.eventSubscriber         = eventSubscriber;
     this.writeRepository         = writeRepository;
     this.unitOfWork = unitOfWork;
     this.bus        = bus;
 }
Пример #5
0
 public ReassignWorkItem(
     IEnumerable <IHandleDomainEvent <WorkItemReassignedEvent, WorkItemId> > workItemReassignedHandlers,
     IWriteRepository <WorkItem, WorkItemId> writeRepository,
     IDomainEventSubscriber eventSubscriber, IUnitOfWork unitOfWork)
 {
     this.workItemReassignedHandlers = workItemReassignedHandlers;
     this.writeRepository            = writeRepository;
     this.eventSubscriber            = eventSubscriber;
     this.unitOfWork = unitOfWork;
 }
Пример #6
0
 private void Distribute(IDomainEventSubscriber subscriber, IDomainEvent domainEvent)
 {
     try
     {
         subscriber.Handle(domainEvent);
     }
     catch (Exception ex)
     {
         OnDistributeExceptionEvent(subscriber, domainEvent, ex);
     }
 }
Пример #7
0
    public void Subscribe <T>(IDomainEventSubscriber <T> subscriber)
        where T : DomainEvent
    {
        DomainEventSubscriber <DomainEvent> eventSubscriber;

        eventSubscriber = (DomainEventSubscriber <DomainEvent>)subscriber;
        if (!this.Publishing)
        {
            this.subscribers.Add(eventSubscriber);
        }
    }
        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);
            }
        }
Пример #9
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);
            }
        }
Пример #10
0
 public void Subscribe(IDomainEventSubscriber <IDomainEvent> subscriber)
 {
     Subscribers.Add(subscriber);
 }
Пример #11
0
 private static bool IsEventTypeMatch <T>(T domainEvent, IDomainEventSubscriber <IDomainEvent> subscriber) where T : IDomainEvent
 {
     return(domainEvent.GetType() == subscriber.SubscribedToEventType());
 }
 public DomainEventPublisherSubscriberPair(IDomainEventPublisher publisher, IDomainEventSubscriber subscriber)
 {
     Publisher  = publisher;
     Subscriber = subscriber;
 }
Пример #13
0
 public InMemoryProductsReadModel(IDomainEventSubscriber subscriber)
 {
     this.subscriber = subscriber;
     this.subscriber.Subscribe <ProductAdded>(HandleProductAddedEvent);
 }