Exemple #1
0
        public async Task <IActionResult> PostAsync([FromBody] Event @event)
        {
            @event.Id = Guid.NewGuid();

            await _eventStore.AddAsync(@event);

            return(Accepted());
        }
Exemple #2
0
        public static async Task <Guid> NewAsync(
            this IEventStore store,
            IEnumerable <IEvent> events,
            CancellationToken cancellationToken = default)
        {
            var id = Guid.NewGuid();
            await store.AddAsync(id, events, cancellationToken);

            return(id);
        }
Exemple #3
0
        public static async Task <TAggregate> CreateAsync <TAggregate, TAggregateId>(
            this IEventStore store,
            IEvent @event,
            CancellationToken cancellationToken = default)
            where TAggregate : IAggregate <TAggregateId>, new()
        {
            var aggregate = new TAggregate();
            await store.AddAsync(aggregate.Id, @event, cancellationToken);

            aggregate.Apply(@event);
            return(aggregate);
        }
Exemple #4
0
        public static async Task <TAggregate> CreateAsync <TAggregate, TAggregateId>(
            this IEventStore store,
            IEnumerable <IEvent> events,
            CancellationToken cancellationToken = default)
            where TAggregate : IAggregate <TAggregateId>, new()
        {
            var aggregate = new TAggregate();
            var list      = events.ToList();
            await store.AddAsync(aggregate.Id, list, cancellationToken);

            list.ForEach(aggregate.Apply);
            return(aggregate);
        }
Exemple #5
0
        private async Task PublishCoreAsync(BaseIntegrationEvent @event)
        {
            try
            {
                await _eventStore.AddAsync(@event);

                _listener.OnNewMessage(@event.Id.ToString());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error publishing event id: {EventId}, {@IntegrationEvent}", @event.Id, @event);
            }
        }
Exemple #6
0
        public Task StoreAsync <TAggregate, TId>(TAggregate aggregate, CancellationToken cancellationToken = default)
            where TAggregate : IAggregate <TId>
        {
            _logger.LogTrace("Dequeuing events on aggregate {Id}", aggregate.Id);
            var events = aggregate.DequeueEvents().ToList();

            if (!events.Any())
            {
                return(Task.CompletedTask);
            }

            _logger.LogTrace("Adding events to event store");
            return(_store.AddAsync(aggregate.Id, events, cancellationToken));
        }
        public async Task RaiseEventAsync <T>(T @event, CancellationToken cancellationToken) where T : Event
        {
            try
            {
                await _eventStore.AddAsync(@event, cancellationToken);

                await _mediator.Publish(@event);

                await _eventStore.MarkEventAsPublishedAsync(@event.Id, cancellationToken);
            }
            catch (Exception ex)
            {
                await _eventStore.MarkEventAsFailedAsync(@event.Id, cancellationToken);

                throw ex;
            }
        }
 private async Task SaveTransactionAsync()
 {
     await eventStore.AddAsync(transactionEvent);
 }
 private async Task SaveTransactionAsync()
 {
     await eventStore.AddAsync(createStorageEvent);
 }