Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2015, 09:11 AM
Authorized User
 
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..
 
Old July 4th, 2015, 04:05 AM
Wrox Author
 
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.
 
Old July 4th, 2015, 08:17 AM
Authorized User
 
Join Date: May 2015
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Repository

Thanks for that response.





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





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