Hands-On Software Architecture with C# 8 and .NET Core 3 by Francesco Abbruzzese

Hands-On Software Architecture with C# 8 and .NET Core 3 by Francesco Abbruzzese

Author:Francesco Abbruzzese
Language: eng
Format: epub
Tags: COM051310 - COMPUTERS / Programming Languages / C#, COM051240 - COMPUTERS / Software Development and Engineering / Systems Analysis and Design, COM051440 - COMPUTERS / Software Development and Engineering / Tools
Publisher: Packt Publishing
Published: 2019-11-29T13:34:35+00:00


Before we describe these patterns, we need to understand the concept of aggregates.

Aggregates

So far, we have talked about entities as the units that are processed by a DDD-based business layer. However, several entities can be manipulated and made into single entities. An example of this is a purchase order and all of its items. In fact, it makes absolutely no sense to process a single order item independently of the order it belongs to. This happens because order-items are actually subparts of an order, not independent entities.

There is no transaction that may affect a single order-item without it affecting the order that the item is in. Imagine that two different people in the same company are trying to increase the total quantity of cement but one increases the quantity of type-1 cement (item 1) while the other increases the quantity of type-2 cement (item 2). If each item is processed as an independent entity, both quantities will be increased, which could cause an incoherent purchase order since the total quantity of cement would be increased twice.

On the other hand, if the whole order, along with all its order-items, is loaded and saved with every single transaction by both people, one of the two will overwrite the changes of the other one, so whoever makes the final change will have their requirements set. In a web application, it isn't possible to lock the purchase order for the whole time the user sees and modifies it, so an optimistic concurrency policy is used. For instance, it is enough to add a version number to each purchase order and to do the following:

Read the order without opening any transaction.

Before saving the modified order, we open a transaction and perform a second read.

If the version number of the newly retrieved order differs from the one of the order that was modified by the user, the operation is aborted because someone else modified the order that was shown to the user immediately after the first read. In this case, the user is informed of the problem and the newly retrieved order is shown to the user once more.

If the version number is unchanged, we increase the version number, proceed with the save, and commit the transaction.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.