Where should Domain Service implementations reside in the DDD project structure?
If we have IDomainInterface
and DomainInterface
implementation, should the DomainInterface
implementation reside in the Infrastructure or Core/Domain part of the solution/project ?
Domain service interfaces and their implementation may reside in the domain layer. However, if the domain service implementation depends on infrastructure concerns then by applying the Dependency Inversion Principle, the implementation would live in the infrastructure layer while depending on an interface defined in the domain.
Most domain services will not need to depend on infrastructure concerns and will be used to model use cases that cannot find a natural home within an existing aggregate, but some domain services will.
Repositories are the most common domain services that requires infrastructure knowledge and therefore you will find their implementation living in the infrastructure layer, but there are other examples.
For instance, in the IDDD's Identity & Access bounded context, the EncryptionService interface lives in the domain while the MD5EncryptionService concrete implementation lives in the infrastructure.