Named repositories in DDD

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!


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.


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.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *