View Single Post
  #1 (permalink)  
Old July 3rd, 2015, 09:11 AM
varghesep varghesep is offline
Authorized User
Points: 136, Level: 2
Points: 136, Level: 2 Points: 136, Level: 2 Points: 136, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: May 2015
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Question Repository in Domain

Glad to be back again to ask you another question.

Take a case where I have many aggregates in a domain model. There are many interactions between the aggregates and there are many CRUD operations too. It is a natural tendency to inject a IRepository in a domain model or domain service. You can think of a scenario where the domain service has to read a customer and then read his orders to make a business decision. To get the customer and orders from the persistent media, I can call a repository find method in the domain model.

My question is, is injecting IRepository to domain service or domain model (in an aggregate) anti-pattern?

My understanding is that the layers exit as the following:

App Service
Repository / Domain Service
Domain Model

The domain service or domain model does not have the knowledge of any repository or even a contract. But the App Service does. It is the job of the App service to read any domain entities from the persistent media and pass that to the domain service or domain model. Please correct me if my understanding is not correct.

Last edited by varghesep; July 3rd, 2015 at 09:14 AM..
Reply With Quote