Esempio n. 1
0
        public async Task PublishAsync <TEvent>(TEvent @event) where TEvent : IEvent
        {
            using (var context = _dbContextFactory.Create())
            {
                await context.Events.AddAsync(_eventModelFactory.Create(@event));

                await context.SaveChangesAsync();
            }

            await _eventBusPublisher.PublishAsync(@event);
        }
Esempio n. 2
0
        public async Task <ICollection <GenericEvent <T> > > GetEvents()
        {
            var typeName = typeof(T).Name;

            _logger.Info($"Getting events from events service of type {typeName}");

            var events = await _eventService.GetUnprocessedGenericEvents(typeName);

            var eventModels = events?.Select(x => new GenericEvent <T> {
                Id = x.Id, Payload = _factory.Create <T>(x.Payload), Type = x.Type
            }).ToList();

            return(eventModels);
        }
Esempio n. 3
0
        public async Task SaveAsync(StreamId streamId, IEnumerable <IEventContext <IEvent> > events, CancellationToken cancellationToken = default)
        {
            if (events == null)
            {
                throw new ArgumentNullException(nameof(events));
            }

            using (var context = _dbContextFactory.Create())
            {
                foreach (var @event in events)
                {
                    await context.Events.AddAsync(_eventModelFactory.Create(streamId, @event));
                }

                await context.SaveChangesAsync(cancellationToken);
            }
        }