Today we are working with Stored Procedures to access the database. In order to allow unit testing, we implemented an interface for each group of related stored procedures, for example:

 // etc..

We plan to implement DDD in all projects.

My question is in which DDD layer its best to put the implementation of these interfaces and why?

Please consider that its a huge 4 years project so for now, we will not be able to make changes in how our DAL works. Thanks!

  • 1
    The layer that best facilitates your goals. Jul 19, 2016 at 5:13

2 Answers 2


Onion architecture is one of the possible choices when you use DDD. If you decide to use it, the implementation should be in the infrastructure layer. You can have several implementation of the same interface and inject the required one in your application. IMO the interfaces themselves should be in the Domain layer.

  • 1
    DDD + Onion = <3
    – superhero
    Jul 19, 2016 at 11:56
  • The Infrastructure layer will return Domain entities. Does that make sense? This named repository is not a generic repo... Jul 19, 2016 at 12:29
  • @UriAbramson, yes it does. When onion architecture is used the DB (i.e. infrastructure) is not in the center, but rather an external module. So it is viewed as a component which provides ways to store your domain entities. Your infrastructure layer can have layers itself. For example you can have a data object which is then converted to a domain entity.
    – djvuk
    Jul 19, 2016 at 14:29
  • The analog, of course, is a Repository. The domain model defines the service provider interface, the persistence component implements that interface. Jul 19, 2016 at 15:23

Depends on what your interface returns. Assuming they return domain entities they should go in your domain layer. The actual interface implementations can go in your persistence layer.

When you have your repository interfaces in the domain layer the layers above does not depend on your persistence layer. From a conceptual standpoint the idea that you get "Customer"'s by id, enrolled status belongs in your domain, how to do that is a persistence concern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.