views:

66

answers:

2

Which layer should the repository classes go in? Domain or Infrastructure?

+1  A: 

I guess that depends how You are going to rely on them.

Question is - are You going to allow Yourself to use repositories from inside of domain?
If so - then You are forced to put them in.

I myself like to put them outside of domain. So - typical life cycle of something looks like this =>

UI => Controller => retrieve aggregate root from repo => call logic through aggregate root => if new aggregate root created, add it to repo.

Sometimes controller calls application service that does some additional stuff besides just retrieving root and calling function on it. But idea is same - domain knows nothing about persistence.


While (as I see it) there's nothing wrong with putting repos in domain (or at least abstractions of them), it makes Your domain more aware of persistence. Sometimes that can solve problems, but generally - that will definitely make Your domain more complex.

Use what seems more natural for You and be ready to switch Your ways any time.

Arnis L.
+3  A: 

The repository interfaces are part of the domain. The actual implementation of the interfaces should be part of the infrastructure.

Jonas Kongslund
Well put. The interfaces are part of the domain, because it is defining the contract by which the DOs will be accessible. It is too often overlooked.
joseph.ferris