R
R
red_gorilla2018-03-27 21:17:40
Java
red_gorilla, 2018-03-27 21:17:40

DDD, aggregate root, entity, repository?

Evans' book says that "repositories" should only return "aggregate root". And how then to be with normal entities. A simple example: there is a City class, by definition it is an entity, it has an id and its name is not unique, how to get it, add it, change it in the DDD "paradigm"? It turns out that each entity needs its own repository and not just for aggregation roots?
For example, a piece of a simple online store, does it turn out that both tag and region have their own repositories? because somehow you need to create them, change them, etc.

public class Tag {
  private string _name ;
}

public class Region {
  private string _name 
}

public class City {
  private Guid _id;
  private string _name 
private Region _region;
}

public class User {
  private Guid _id;
  private City _city; 

   // всякие методы
}
public class Product {
  private Guid _id;
  private City[] _cities; 
  private Tag[] _tags;
  
   // всякие методы
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dmitriy, 2018-03-27
@dmitriylanets

I use my own repository for each entity, since the repository has basic crud methods that allow, for example, to build a table with a list of entities, when creating a table object, an entity repository with a contract of the CRUD methods interface is transferred. I can’t imagine how it would have turned out working only with the unit, although there have been attempts in this direction.

D
ddd329, 2018-04-01
@ddd329

Well, then the AGGREGATE will consist of one ENTITY - City

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question