Esempio n. 1
0
        async Task IConsumer <CreateEvent> .Consume(ConsumeContext <CreateEvent> context)
        {
            var command = context.Message;

            using (var session = await repository.BeginSessionFor(command.EventId, false))
            {
                if (session == null)
                {
                    // throw exception
                }

                if (!session.IsNewState)
                {
                    // throw concurrency exception
                }
                var state = session.GetCurrentState();

                var events = aggregate.CreateEvent(state, command.EventId, command.Title, command.Description);

                session.AddEvents(events);

                await session.SaveChanges();
            }
        }