<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://thoughtshapes.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>ThoughtShapes - Where Should My Repository Live? - Comments</title>
 <link>http://thoughtshapes.com/node/21</link>
 <description>Comments for &quot;Where Should My Repository Live?&quot;</description>
 <language>en</language>
<item>
 <title>Thank you for taking the</title>
 <link>http://thoughtshapes.com/node/21#comment-598</link>
 <description>&lt;p&gt;Thank you for taking the time to respond. Everything you said makes perfect sense, and it is nice to have this type of validation when coding DDD. &lt;/p&gt;
&lt;p&gt;I believe passing the Repository to the constructor makes more sense because we should argue that the Customer does not have the “knowledge” to know which repository to create, and therefore it is logical for CustomerFactory to do this job (and it works better with unit tests). So I agree with all your point.&lt;/p&gt;
&lt;p&gt;At this point, I am trying to use NHibrante to implement a prototype on this idea. When I am done, I will post it on my blog (&lt;a href=&quot;http://mikeperetz.blogspot.com/&quot; title=&quot;http://mikeperetz.blogspot.com/&quot;&gt;http://mikeperetz.blogspot.com/&lt;/a&gt;) I would love your feedback on it.&lt;/p&gt;
</description>
 <pubDate>Mon, 19 Nov 2007 22:01:51 -0500</pubDate>
 <dc:creator>Anonymous</dc:creator>
 <guid isPermaLink="false">comment 598 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>Thanks for the complement on</title>
 <link>http://thoughtshapes.com/node/21#comment-597</link>
 <description>&lt;p&gt;Thanks for the complement on the article.  &lt;/p&gt;
&lt;p&gt;You raise an interesting (and common) problem.  If I were to implement lazy loading here to deal with the customer who had placed a million orders I would allow the Customer class to interact with an interface to an order repository (IOrderRepository).  It would obtain an implemenation of that interface by calling a repository factory object to get the concrete implemenation and then use that to retrieve a smaller subset of the data.  Using your example of a date range I would implement the customer get order method like so:&lt;/p&gt;
&lt;pre class=&quot;code cs&quot;&gt;
public class Customer
{
      IList GetOrders(DateTime from, DateTime to)
      {
           return RepositoryFactory.OrderRepository.GetOrders(this, from, to);
       }
}&lt;/pre&gt;&lt;p&gt;
Now since the Customer class is really referring to an IOrderRepository, I&#039;d say that the Repository interface lives in the domain (with its client), and the concrete implementations live in their own namespaces (and probably assemblies).  &lt;/p&gt;
&lt;p&gt;Note that although I&#039;m using a RepositoryFactory in this example, I might provide the indirection by just passing the IOrderRepository to the Customer when I created it.  (This implies that whatever object created the Customer object would get the concrete implementation from the RepositoryFactory because we still want that run-time configurability.)   I usually determine whether or not to pass the repository instances to the object on its constructor or have it use the RepositoryFactory directly based upon whether the object uses multiple repositories.  If it uses one or two different repositories, I pass the instances, otherwise I just have the object use the RepositoryFactory to get the instances.&lt;/p&gt;
&lt;p&gt;Does that make sense to you?&lt;/p&gt;
</description>
 <pubDate>Mon, 19 Nov 2007 12:19:00 -0500</pubDate>
 <dc:creator>Rob Scott</dc:creator>
 <guid isPermaLink="false">comment 597 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>First of all, you wrote a</title>
 <link>http://thoughtshapes.com/node/21#comment-596</link>
 <description>&lt;p&gt;First of all, you wrote a very nice article. I think you are touching very fundamental issues. I am studying DDD now, and having trouble with a few scenarios.&lt;/p&gt;
&lt;p&gt;Where do Repositories live? I feel that I am very limited if the repositories live within the Application layer only. I think lazy loading becomes a must in one point, because you don’t want to bring too much data from the database.&lt;/p&gt;
&lt;p&gt;I also feel, that if you were to implement Specification pattern (Evens), then again you need the Repositories. Having said that, I think you should only use interfaces to them, and never use their true implementation. &lt;/p&gt;
&lt;p&gt;When coding I sometime have a “the million rule”, what if there is a million orders to a customer. Or what if there are a million history records for a transaction. We should never bring that type of data down. We should probably use Query Pattern, which will work with Repositories.&lt;/p&gt;
&lt;p&gt;Now I wonder, if I was to create a Customer and Order classes… does this makes snese?&lt;/p&gt;
&lt;p&gt;List orders = customer.GetOrders(); // use Repository to implement this&lt;br /&gt;
Or&lt;br /&gt;
List order = customer.GetOrders(DateTime fromDate) // use Repository with Query pattern&lt;/p&gt;
&lt;p&gt;What about adding an order?&lt;br /&gt;
customer.AddNewOrder(order);&lt;/p&gt;
&lt;p&gt;Does code like that is DDD? If yes, the Repositories do live within the domain… &lt;/p&gt;
&lt;p&gt;What is your take on this?&lt;br /&gt;
(Let’s assume that you can have a million orders per customer)&lt;/p&gt;
</description>
 <pubDate>Sun, 18 Nov 2007 10:10:13 -0500</pubDate>
 <dc:creator>Anonymous</dc:creator>
 <guid isPermaLink="false">comment 596 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>Where Should My Repository Live?</title>
 <link>http://thoughtshapes.com/node/21</link>
 <description>&lt;p&gt;
Adherents to Domain Driven Design (DDD) often struggle with how to structure the “layers” of their application with respect to where object repositories should be placed.  As usual in software development the answer to this quandary is “It depends”.  In this posting I’ll discuss several things that should be taken into consideration when making this decision.
&lt;/p&gt;
&lt;p&gt;&lt;p&gt;&lt;a href=&quot;http://thoughtshapes.com/node/21&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://thoughtshapes.com/node/21#comments</comments>
 <category domain="http://thoughtshapes.com/taxonomy/term/6">Design</category>
 <category domain="http://thoughtshapes.com/taxonomy/term/3">Patterns</category>
 <category domain="http://thoughtshapes.com/taxonomy/term/4">TDD</category>
 <pubDate>Mon, 19 Mar 2007 13:20:00 -0400</pubDate>
 <dc:creator>Rob Scott</dc:creator>
 <guid isPermaLink="false">21 at http://thoughtshapes.com</guid>
</item>
</channel>
</rss>
