Can I update multiple instances of an aggregate of the same type in a single transaction?

Sorry if it is duplicated, I searched a lot in SO, but I did not find a matching question.

I know that we should not update multiple instances of a population in one transaction. However, I think that “multiple aggregate instances” here means a multiple instance of different types of aggregates. I'm right?

Let's say Product and BacklogItem are two different aggregates, so we should avoid updating both Product and BacklogItem in a single transaction.

But what if I need to update multiple instances of the same aggregate type? Say I need to update all products . What is the best way to handle this?

pseudo code

//Application Service
public void ChangeTitle(string newName)
{
    using(uow.BeginTransaction())
    {
         IEnumerable<Product> products = repo.GetAll();
         foreach(var product in products)
         {
             product.ChangeName(newName);
         }
    }
}
+4
source share
3 answers

The type of AR does not matter; ARs are always transactional boundaries. When dealing with many of them, you should usually accept partial failures and a possible sequence.

, AR. , , . - concurrency, , , ?

, , AR, , , - concurrency ( , ).

AR , , AR, .

+3

. , , , , , :

  • - concurrency, concurrency
  • - , concurrency
  • , concurrency

, ( ) ( ). , , , , , , ?

DDD - , . , , .

0

. , , .

, ? , , . , , , , . " renamer" - ?

I would simulate such a massive renamer so that it registers as a consumer of all domain events from the aggregates that need to be updated, and then updates the name of these aggregates (potentially in parallel), and then continues to listen for domain events. When all events are received, he can report that he has completed the renaming of all aggregates and has completed the exception handling.

0
source

Source: https://habr.com/ru/post/1669099/


All Articles