Search code examples
c#domain-driven-designddd-repositories

Does repository implementation be a part of infrastructure?


In a DDD project, I have this structure:

Infrastructure

  • MyProj.Library (contains helper methods)
  • MyProj.Factory (contains methods for IoC and DI)
  • MyProj.Data (contains an implementation of IUserRepository)

Domain

  • MyProj.Domain (contains the domain aggregates and repository interfaces, i.e. IUserRepository)

Application

  • MyProj.WebAPI

I need to know if MyProj.Data belongs to the Infrastructure layer or Domain layer. I am really confused where the implemented repositories belongs.


Solution

  • Typically you would have the repository implementation in the infrastructure layer and the repository interfaces in the domain layer.

    As an example, have a look at the Onion Architecture which states

    Inner layers define interfaces. Outer layers implement interfaces

    Onion Architecture

    In this simple implementation of the Onion Architecture, the VisitorRepository is residing in the Infrastructure layer and implements IVisitorRepository found in the Core (Domain) layer.