Search code examples
domain-driven-designmicroservicesdata-access-layerentities

In a DDD oriented microservice the Infrastructure and Entities can be reused?


I'm thinking in a DDD oriented microservice architecture as described in this article (https://learn.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/ddd-oriented-microservice). But I'm in doubt about the data access and the entities.

Would it make sense for me to put domain entities and data access into a common project or even into a nugget? Because I think I would be rewriting the same data access multiple times for each service.


Solution

  • No matter if you use DDD or not, the four tenets of SOA are:

    • Services have explicit boundaries
    • Services are autonomous
    • Services share schema and contract, not class
    • Services interoperate based on policy

    One of the consequences of this is that services never share their persistence.

    There are discussions about how service boundaries align with bounded contexts, but you can start simple and have one-to-one alignment to start with and bounded context is also something that never exposes it's persistence in any other way than using contracts.