Home > database >  What is DDD's Aggregate in SpringBoot MVC?
What is DDD's Aggregate in SpringBoot MVC?

Time:02-09

Suppose I've a bunch of microservices, each written on SpringBoot MVC (REST, Controller, Service, etc..)

Can anybody explain what is DDD's Aggregate in SpringBoot MVC? is it a controller? Or is it a specific microservice which is a root for some other microservices?

In other words, is aggregate something within a service with a controller's endpoint as a root? or is aggregate a sub-set of microservices with a particular SpringBoot application/service as an entry point to them?

CodePudding user response:

Two things here.

Spring MVC is a boundary layer to translate between HTTP and internals of the app. The internals are where all the DDD happens, not the boundary itself

Spring Boot is for bootstrapping an application with all the common tools and making a runnable deployment unit.

So, in case of DDD an HTTP request comes to Spring MVC layer, there a domain request is instantiated and passed to domain core for execution. Domain response then comes back and is translated into HTTP response by Spring MVC layer.

CodePudding user response:

It is neither a controller nor specific microservice.

It is a cluster of the domain objects that can be treated as a single unit (e.g. Order and its order line) (see this) which is retrieved , saved and searched by the repository.

The spring framework also provides an more specialised @Component called @Repository to represent the repository concepts (quoted from its javadoc) :

Indicates that an annotated class is a "Repository", originally defined by Domain-Driven Design (Evans, 2003) as "a mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects".

Teams implementing traditional Java EE patterns such as "Data Access Object" may also apply this stereotype to DAO classes, though care should be taken to understand the distinction between Data Access Object and DDD-style repositories before doing so. This annotation is a general-purpose stereotype and individual teams may narrow their semantics and use as appropriate.

As we use repository to save JPA @Entity or MongoDB @Document to the underlying datastore , so DDD aggregate is more align to them

  •  Tags:  
  • Related