Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Question: How event faults are processed #29

Closed
pblachut opened this issue Aug 15, 2018 · 3 comments
Closed

Question: How event faults are processed #29

pblachut opened this issue Aug 15, 2018 · 3 comments
Assignees
Labels

Comments

@pblachut
Copy link

pblachut commented Aug 15, 2018

This is a question rather than issue.

As far as I was able to read from the source code, when the events are produced by the aggregate then they are saved in event store and published by the event publisher:

public void SendAndPublish<TCommand, TAggregate>(TCommand command) 
            where TCommand : IDomainCommand 
            where TAggregate : IAggregateRoot
        {
            if (command == null)
                throw new ArgumentNullException(nameof(command));

            var handler = _handlerResolver.ResolveHandler<ICommandHandlerWithDomainEvents<TCommand>>();

            _commandStore.SaveCommand<TAggregate>(command);

            var events = handler.Handle(command);

            foreach (var @event in events)
            {
                @event.CommandId = command.Id;
                var concreteEvent = _eventFactory.CreateConcreteEvent(@event);
                _eventStore.SaveEvent<TAggregate>((IDomainEvent)concreteEvent);
                _eventPublisher.Publish(concreteEvent);
            }
        }

This comes to me with an conclusion that there is no transaction during saving these events to the event store either publishing then on the bus / updating read model.
When save of single event will fail then save of previous ones will not be compensated. Similar situstion os without read model. Can you confirm that?

@lucabriguglia
Copy link
Owner

You are right, there is no transaction for the events.
But the possibility of having more than one event as a result of a command handler is very low.
I decided to have a list of domain events as result just to give the framework more flexibilty.
Also, it would be something not support by all data providers.
Regarding the read model, if you want it to be immediately consistent you could save it in the command handler along with the write model using the same transaction.

@lucabriguglia
Copy link
Owner

As System.Transactions is now supported in EF Core 2.1, I'll add support to transactions.

@lucabriguglia
Copy link
Owner

lucabriguglia commented Aug 20, 2018

Closing this issue as I've created a new issue #32 for transactions support.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants