Contents
What is DDD repository?
In DDD, a repository is an objcect that participates in the domain but really abstracts away storage and infrastructure details. Most systems have a persistent storage like a database for its fully functioning. Applying repositories happens by integrating and synchronizing with existing aggregate objects in the system.
Can a repository return a value object?
The repository interfaces that support your read use cases return value objects (objects where the internal state is immutable). In some cases, it can make sense to have the repository just return a representation.
What is DDD oriented Microservice?
Domain-driven design (DDD) advocates modeling based on the reality of business as relevant to your use cases. In the context of building applications, DDD talks about problems as domains. In addition, DDD approaches should be applied only if you are implementing complex microservices with significant business rules.
How are value objects persisted in the database?
However, the persistence of that value object into the database was performed like a regular entity in a different table. With EF Core 2.0 and later, there are new and better ways to persist value objects.
How are value objects defined in domain model?
However, value objects are usually serialized and deserialized to go through message queues, and being read-only stops the deserializer from assigning values, so you just leave them as private set, which is read-only enough to be practical. You just saw how to define a value object in your domain model.
How to implement value objects with no ID?
You can see how this value object implementation of Address has no identity and therefore, no ID field, neither at the Address class not even at the ValueObject class. Having no ID field in a class to be used by Entity Framework (EF) was not possible until EF Core 2.0, which greatly helps to implement better value objects with no ID.
How is an implementation of a value object?
In terms of implementation, you can have a value object base class that has basic utility methods like equality based on the comparison between all the attributes (since a value object must not be based on identity) and other fundamental characteristics.