public async Task SaveAsync(ICommand command, CancellationToken cancellationToken = default)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var type = command.GetType();
            var data = _commandSerializer.Serialize(command);

            using (var context = _dbContextFactory.Create())
            {
                await context.Commands.AddAsync(new Entities.Command
                {
                    Name          = type.Name,
                    Type          = type.FullName,
                    Subject       = command.Subject,
                    CorrelationId = command.CorrelationId,
                    Data          = data,
                    Id            = command.Id,
                    UserId        = command.Actor,
                    Timestamp     = command.Timestamp,
                });

                await context.SaveChangesAsync(cancellationToken);
            }
        }
Exemplo n.º 2
0
        public async Task SaveAsync <TQueryResult>(IQuery <TQueryResult> query, CancellationToken cancellationToken = default)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            var type = query.GetType();
            var data = _querySerializer.Serialize(query);

            using (var context = _dbContextFactory.Create())
            {
                await context.Queries.AddAsync(new Query
                {
                    Name          = type.Name,
                    Type          = type.FullName,
                    Data          = data,
                    Id            = query.Id,
                    CorrelationId = query.CorrelationId,
                    Timestamp     = query.Timestamp,
                    UserId        = query.Actor,
                });

                await context.SaveChangesAsync(cancellationToken);
            }
        }
Exemplo n.º 3
0
        public async Task <long> CountAsync(StreamId streamId, CancellationToken cancellationToken = default)
        {
            using (var context = _dbContextFactory.Create())
            {
                var count = await context.Events.LongCountAsync(@event => @event.StreamId == streamId, cancellationToken);

                return(count);
            }
        }