Search code examples
.netmappingautomappercouchdbclean-architecture

What is correct approach to mapping entities to CouchDB documents in a clean architecture?


I would like to use a Clean Architecture approach in my .NET Core Service - particularly, separate my entities and aggregates from CouchDocument models.

If I understood correctly, then I should do the following:

  1. Define the IRepository interface, where TEntity is an entity or aggregate.
  2. Implement CouchDbRepository<TEntity , TCouchDocument>
  3. Configure mapping of CouchDb entities and documents in CouchDbRepository All this is needed to avoid dragging dependencies into Core

Can this be done? Or is there a better approach? And where is it better to implement specifications to obtain filtered data, in a custom CouchDbRepository or through expression mapping?


Solution

  • Using the repository pattern to decouple domain and application logic from specific storage technologies is a quite common approach in Clean Architecture.

    So yes, your proposal seems reasonable. To not violate the dependency rule of CA the repository interface should be in the application layer and the repository implementation in the frameworks or I/O layer.

    For a more detailed discussion on how to implement repository pattern correctly in CA, pls also see: https://youtu.be/pfhDO_hZixw