Exemplo n.º 1
0
        public Task Handle(CompleteTaskCommand command)
        {
            var @event = new TaskFinished
            {
                Number    = command.TaskNumber,
                Timestamp = DateTimeOffset.UtcNow
            };

            // If some other process magically zips
            // in and updates this project event stream
            // between the call to AppendOptimistic()
            // and SaveChangesAsync(), Marten will detect
            // that and reject the transaction
            _session.Events.AppendOptimistic(
                command.ProjectId,
                @event);
            return(_session.SaveChangesAsync());
        }
Exemplo n.º 2
0
        public Task Handle(CompleteTaskCommand command)
        {
            var @event = new TaskFinished
            {
                Number    = command.TaskNumber,
                Timestamp = DateTimeOffset.UtcNow
            };

            // This tries to acquire an exclusive
            // lock on the stream identified by
            // command.ProjectId in the database
            // so that only one process at a time
            // can update this event stream
            _session.Events.AppendExclusive(
                command.ProjectId,
                @event);
            return(_session.SaveChangesAsync());
        }
Exemplo n.º 3
0
        public Task Handle(CompleteTaskCommand command)
        {
            var @event = new TaskFinished
            {
                Number    = command.TaskNumber,
                Timestamp = DateTimeOffset.UtcNow
            };

            _session.Events.Append(
                command.ProjectId,

                // Using this overload will make Marten do
                // an optimistic concurrency check against
                // the existing version of the project event
                // stream as it commits
                command.ExpectedVersion,
                @event);
            return(_session.SaveChangesAsync());
        }