/// <summary> /// 订阅领域事件 /// </summary> /// <param name="subscriber"></param> public void Subscribe(IDomainEventSubscriber <IDomainEvent> subscriber) { if (!this.publishing) { this.Subscribers.Add(subscriber); } }
/// <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); }
protected virtual void OnDistributeExceptionEvent(IDomainEventSubscriber subscriber, IDomainEvent domainEvent, Exception exception) { var handler = DistributeExceptionEvent; if (handler != null) { handler(subscriber, domainEvent, exception); } }
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; }
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; }
private void Distribute(IDomainEventSubscriber subscriber, IDomainEvent domainEvent) { try { subscriber.Handle(domainEvent); } catch (Exception ex) { OnDistributeExceptionEvent(subscriber, domainEvent, ex); } }
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); } }
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 <IDomainEvent> subscriber) { Subscribers.Add(subscriber); }
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; }
public InMemoryProductsReadModel(IDomainEventSubscriber subscriber) { this.subscriber = subscriber; this.subscriber.Subscribe <ProductAdded>(HandleProductAddedEvent); }