Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does an IRepository interface belong?

In a typical 3 layered system, GUI->DOMAIN->DAL, where does the IRepository belong? Does it belong in the DOMAIN or the DAL. I don't know enough about orthogonality and service layers to know what the difference is.(edit)Allow me to clarify. Where(In what layer?) should the IRepository interface be defined? Also in what layer should the IRepository be implemented? Allow me to clarify even further...I am trying to blend Fowlers "Seperated Interface" with IRepository. My concern is enforcing dependancy rules. If the IRepository is defined in the DOMAIN, then the DAL package will have a dependancy on the DOMAIN. Else, if vice versa, the IRepository is defined in the DAL, then the DOMAIN will have a dependancy on the DAL. Again, where does the IRepository belong? This is my 3rd edit.

like image 903
dannyrosalex Avatar asked Feb 24 '23 19:02

dannyrosalex


2 Answers

Usually, IRepository (or rather specific interfaces like IUserRepository) belongs to DOMAIN layer. Repository is specific to a DOMAIN layer and is intended to work with aggregate roots. Hence the location. But implementation of IRepository belongs to DAL of course. You can then use IoC to glue everything together.

like image 81
Kostassoid Avatar answered Mar 15 '23 00:03

Kostassoid


Since repository deals with retrieving and persisting data, the correct layer will be the DAL.

like image 34
boca Avatar answered Mar 15 '23 02:03

boca