Example #1
0
        private async Task Save(ICanApplyEvents canApplyEvents, string correlationId, string causationId)
        {
            var commitHeaders = new Dictionary <string, object>();

            var metaData = _environment.GetMetaData().MetaData;

            foreach (var item in metaData)
            {
                commitHeaders[item.Key] = item.Value;
            }

            if (!string.IsNullOrEmpty(correlationId))
            {
                commitHeaders[CorrelationIdKey] = correlationId;
            }

            if (!string.IsNullOrEmpty(causationId))
            {
                commitHeaders[CausationIdKey] = causationId;
            }

            commitHeaders[EntityClrTypeHeader] = canApplyEvents.GetType().AssemblyQualifiedName;
            commitHeaders[EntityIdHeader]      = canApplyEvents.Id;

            _environment.GetSettings <EventStoreSettings>().ModifyHeaders(commitHeaders);

            var streamName = canApplyEvents.GetStreamName(_environment);
            var events     = canApplyEvents.GetAppliedEvents().ToList();

            await SaveEventsToStream(streamName, ExpectedVersion.Any, events.Select(x => new Event(x.Id, x.Instance)).ToList(), commitHeaders).ConfigureAwait(false);

            canApplyEvents.ClearAppliedEvents();
        }
Example #2
0
 public LoadedEventAwareItem(ICanApplyEvents canApplyEvents, string correlationId, string causationId)
 {
     CanApplyEvents = canApplyEvents;
     CorrelationId  = correlationId;
     CausationId    = causationId;
 }
Example #3
0
 public void Attach(ICanApplyEvents canApplyEvents)
 {
     _loadedEventAwareItems.Push(new LoadedEventAwareItem(canApplyEvents, _environment.GetCorrelationId(), _environment.GetCausationId()));
 }
Example #4
0
 public void Track(ICanApplyEvents canApplyEvents)
 {
     _repository.Attach(canApplyEvents);
 }