Beispiel #1
0
        private async Task UpdatePosition(Position newPosition)
        {
            using var scope           = _serviceProvider.CreateScope();
            await using var dbContext = scope.ServiceProvider.GetRequiredService <GameSociationContext>();
            var currentPosition = await dbContext.Set <Position>().AsNoTracking().SingleOrDefaultAsync(p => p.Type == PositionType.DomainEvent);

            if (currentPosition == null)
            {
                await dbContext.AddAsync(newPosition);
            }
            else
            {
                currentPosition.Commit  = newPosition.Commit;
                currentPosition.Prepare = newPosition.Prepare;
            }

            await dbContext.SaveChangesAsync();
        }
Beispiel #2
0
        private async Task HandleEvent(StreamSubscription subscription, ResolvedEvent resolvedEvent, CancellationToken cancellationToken)
        {
            if (!resolvedEvent.OriginalPosition.HasValue)
            {
                return;
            }

            var domainEvent = resolvedEvent.ToTypedEvent();
            await ProjectionNormalizer.ApplyEvent(domainEvent);

            var newPosition = new Position
            {
                Commit  = resolvedEvent.OriginalPosition.Value.CommitPosition,
                Prepare = resolvedEvent.OriginalPosition.Value.PreparePosition,
                Type    = PositionType.ReadModel
            };

            await UpdatePosition(newPosition);
        }
Beispiel #3
0
        private async Task HandleEvent(StreamSubscription subscription, ResolvedEvent resolvedEvent, CancellationToken cancellationToken)
        {
            if (!resolvedEvent.OriginalPosition.HasValue)
            {
                return;
            }

            var domainEvent = resolvedEvent.ToTypedEvent();

            using var scope = _serviceProvider.CreateScope();
            var eventBus = scope.ServiceProvider.GetRequiredService <IEventBus>();

            await eventBus.Publish((IDomainEvent)domainEvent);

            var newPosition = new Position
            {
                Commit  = resolvedEvent.OriginalPosition.Value.CommitPosition,
                Prepare = resolvedEvent.OriginalPosition.Value.PreparePosition,
                Type    = PositionType.DomainEvent
            };

            await UpdatePosition(newPosition);
        }
Beispiel #4
0
 protected abstract Task UpdatePosition(Position newPosition);