예제 #1
0
    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);
    }
예제 #2
0
    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);
    }
예제 #3
0
    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)
                );
        }
    }
예제 #4
0
 protected virtual void AddDistributedEvent(object eventData)
 {
     _distributedEvents.Add(new DomainEventRecord(eventData, EventOrderGenerator.GetNext()));
 }
예제 #5
0
 protected virtual void AddLocalEvent(object eventData)
 {
     _localEvents.Add(new DomainEventRecord(eventData, EventOrderGenerator.GetNext()));
 }