예제 #1
0
 private void StoreEvent <TId, TEvent>(Type aggregateType, TId aggregateId, TEvent @event)
 {
     if (_eventStore == null)
     {
         throw new ApplicationException("Event Store is not configured. Use 'EventBus.Instance.Configure(eventStore, eventSerializationStrategy);' to configure it.");
     }
     try
     {
         if (_checkLatestEventTimestampPriorToSavingToEventStore)
         {
             var latestCreatedOnInEventStore = _eventStore.LatestEventTimestamp(aggregateId);
             if (DateTime.Compare(DateTime.UtcNow, latestCreatedOnInEventStore) < 0)
             //earlier than in event store
             {
                 var serializedAggregateId = _eventSerializationStrategy.SerializeEvent(aggregateId);
                 Publish(GetType(), aggregateId, new AggregateCacheCleared(serializedAggregateId, typeof(TId), aggregateType));
             }
         }
         _eventStore.Save(new AggregateEvent
         {
             Id                    = Guid.NewGuid(),
             AggregateType         = aggregateType.AssemblyQualifiedName,
             EventType             = typeof(TEvent).AssemblyQualifiedName,
             CreatedOn             = DateTime.UtcNow,
             SerializedEvent       = _eventSerializationStrategy.SerializeEvent(@event),
             SerializedAggregateId = _eventSerializationStrategy.SerializeEvent(aggregateId),
             AggregateIdType       = typeof(TId).AssemblyQualifiedName
         });
     }
     catch (Exception ex)
     {
         throw new ApplicationException("DDD.Light.CQRS.InProcess.EventBus -> StoreEvent<T>: Saving to event store failed", ex);
     }
 }
예제 #2
0
 private void StoreEvent <TId, TEvent>(Type aggregateType, TId aggregateId, TEvent @event)
 {
     if (_eventStore != null)
     {
         _eventStore.Save(new AggregateEvent
         {
             Id                    = Guid.NewGuid(),
             AggregateType         = aggregateType.AssemblyQualifiedName,
             EventType             = typeof(TEvent).AssemblyQualifiedName,
             CreatedOn             = DateTime.UtcNow,
             SerializedEvent       = _eventSerializationStrategy.SerializeEvent(@event),
             SerializedAggregateId = _eventSerializationStrategy.SerializeEvent(aggregateId),
             AggregateIdType       = typeof(TId).AssemblyQualifiedName
         });
     }
 }