JD.
JD.

Reputation: 15561

Is this the correct way to use Domain Events in DDD?

I have a design question which I think Domain events will solve but I need to make sure I am going about it the correct way and that I understand Domain events correctly.

I have a change in one aggregate root which needs to make a change in the another aggregate root.

So when I make a change in my initiating aggregate root I will fire a domain event which will apply the change in the other aggregate root. If all goes well I have two database transactions which will be persisted.

Now if one fails (say the second), how do I resolve this or if the second goes through but my initiating change fails to persist?

I am assuming this is a single user system where everything happens synchronously so the second aggregate is committed before the first initiating aggregate.

JD

Upvotes: 1

Views: 787

Answers (1)

xelibrion
xelibrion

Reputation: 2234

It depends on how you have organized Unit of Work management in your application. In web app Unit of Work should be created every request and in this case you usually have one transaction within http request, which will be committed or rolled back after end of request.

Of course you can create two separate transaction, but I do not recommend to do it inside your web app. In this case (if I would have such requirements) would rather use messaging architecture (take a look at http://www.nservicebus.com/ or http://masstransit-project.com/)

Upvotes: 3

Related Questions