How should the rules for Aggregate Roots apply?

While searching the Internet, I came across a list of rules from Eric Evans' book, which should be applied to aggregates:

  • The root entity has global identity and is ultimately responsible for checking invariants
  • Root objects have global identity. Objects inside the border have a local identity, the only one inside the Unit.
  • Nothing outside the Aggregate boundary can contain a link to anything inside except the root Entity. The root object can transfer references to internal objects to other objects, but they can only use them temporarily (within the framework of one method or block).
  • Only aggregated roots can be obtained directly with database queries. Everything else must be done by going around.
  • Objects within the aggregate may contain links to other roots of the aggregate.
  • The delete operation should delete everything within the boundaries of the population at the same time.
  • When there is a transition to any object within the boundaries of the Aggregate, all invariants of the whole set must be satisfied.

All this seems perfect in theory, but I don’t see how these rules will be enforced in the real world.

Take rule 3, for example. As soon as the root object gave the external object a link to the internal object, what to hold this external object in the link for a single method or block?

(If enforcing this is platform specific, I would be interested to know how it will be implemented in C # /. NET / NHibernate.)

+5
5

, .

, , .

: . , . , , .

: ? . : , , .

+6

, . , .

0

( , ), , , . , NHibernate, , , , , Event Sourcing, , , - , , .

  • . , .

:: GUID . . -. GUID - , .

  • Aggregate - , Entity. Entity , ( ).

:: . , , . , # - , root. , - , . , , / . ORM, , . internal NHibernate, , . , (, , ), , DTO, NHibernate, DTO . , , .

( , ), ( ), , , . , Visual Studio, , .

  • . .

:: , , root, IEntity, . AggregateRoot, IEntity. " - ". AggregateRoot. , , - shhennaniganry. "traversal"

  • .

:: - "". . , "" RootB RootA, RootA RootB, . , , RootB RootA, RootA , RootB .

:: , -. , , . . , . , , . - . , , , , , , , - . , , " ". , . , , , , .. . , , Aggregate Root , , , , , .

  • , .

:: . . , , root , - . , , , ActionA(), - - - , . , () . , , ( ) . , ( ), -. , , () , .

, , , . , , . , root A B (mementos), . RootA, . RootB, (, - ). RootB, , , . - RootA ( - ), , (, ). - , (.: ), . . , DDD, , /.

, 8 , , - .

0

, , .

0

DDD - . , .

, , FluentNHibernate .

Your example can be implemented by marking all aggregate roots using the IAggregateRoot marker interface and third parties with the IEntity marker interface. Then your normal FNH convention will check for entities marked as IEntity objects that reference IEntity objects, and when they are found they will signal an error (for example, throw an exception).

Is there any reason?

-1
source

All Articles