Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Patterns, Principles and Practices of Domain-Driven Design
This is the forum to discuss the Wrox book Patterns, Principles and Practices of Domain-Driven Design by Scott Millett; ISBN: 978-1-118-71470-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Patterns, Principles and Practices of Domain-Driven Design section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 3rd, 2015, 09:11 AM
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
  #2 (permalink)  
Old July 4th, 2015, 04:05 AM
Wrox Author
Points: 237, Level: 4
Points: 237, Level: 4 Points: 237, Level: 4 Points: 237, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2015
Posts: 59
Thanks: 1
Thanked 5 Times in 5 Posts
Default

Hi,

Glad to have you back :)

Repositories are a tricky subject to be fair. Should repository interfaces live in the domain or service layer? It depends.

For me, I would try and keep repositories completely out of the domain. I think that's the ideal, because they are an implementation detail. However, sometimes you need to run queries as part of your domain logic. And so, you almost have to have a repository in the domain so it can be called from within a domain service.

If you ask a handful of DDD practitioners, even those talking at conferences etc, I would expect some will say repositories in the domain, others will say keep them out.

Basically, my opinion is, if you can keep them out... keep them out. If not, don't be afraid to put them in the domain model.
Reply With Quote
  #3 (permalink)  
Old July 4th, 2015, 08:17 AM
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
Default Repository

Thanks for that response.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AppService -> Domain Service -> Repository samvan BOOK: Professional ASP.NET Design Patterns 5 January 13th, 2012 08:18 AM
Make Your Own Plugin Repository leepettijohn BOOK: Professional WordPress Plugin Development 0 September 15th, 2011 05:55 PM
Changes needed for Linq2Sql Repository? ksouthworth BOOK: Professional ASP.NET Design Patterns 1 December 14th, 2010 10:16 AM
SVN Repository Hannes BOOK: Professional Joomla! ISBN: 978-0-470-13394-1 2 August 30th, 2010 05:17 AM
Same pages for sub domain from main domain vivek_inos ASP.NET 1.0 and 1.1 Professional 1 February 13th, 2007 10:15 AM



All times are GMT -4. The time now is 05:12 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.