public async Task PublishAsync( Type eventType, object eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true) { if (onUnitOfWorkComplete && UnitOfWorkManager.Current != null) { AddToUnitOfWork( UnitOfWorkManager.Current, new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext(), useOutbox) ); return; } if (useOutbox) { if (await AddToOutboxAsync(eventType, eventData)) { return; } } await PublishToEventBusAsync(eventType, eventData); }
public async Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true) { if (onUnitOfWorkComplete && UnitOfWorkManager.Current != null) { AddToUnitOfWork( UnitOfWorkManager.Current, new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext()) ); return; } await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete : false); }
protected virtual void TriggerEventWithEntity( IEventBus eventPublisher, Type genericEventType, object entityOrEto, object originalEntity) { var entityType = ProxyHelper.UnProxy(entityOrEto).GetType(); var eventType = genericEventType.MakeGenericType(entityType); var eventData = Activator.CreateInstance(eventType, entityOrEto); var currentUow = UnitOfWorkManager.Current; if (currentUow == null) { Logger.LogWarning("UnitOfWorkManager.Current is null! Can not publish the event."); return; } var eventRecord = new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext()) { Properties = { { UnitOfWorkEventRecordEntityPropName, originalEntity }, } }; /* We are trying to eliminate same events for the same entity. * In this way, for example, we don't trigger update event for an entity multiple times * even if it is updated multiple times in the current UOW. */ if (eventPublisher == DistributedEventBus) { currentUow.AddOrReplaceDistributedEvent( eventRecord, otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) ); } else { currentUow.AddOrReplaceLocalEvent( eventRecord, otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) ); } }
protected virtual void AddDistributedEvent(object eventData) { _distributedEvents.Add(new DomainEventRecord(eventData, EventOrderGenerator.GetNext())); }
protected virtual void AddLocalEvent(object eventData) { _localEvents.Add(new DomainEventRecord(eventData, EventOrderGenerator.GetNext())); }