<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Don&#8217;t Create Aggregate Roots</title>
	<atom:link href="http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/</link>
	<description>Enterprise Development Expert &#38; SOA Specialist</description>
	<lastBuildDate>Sat, 11 Feb 2012 15:16:10 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-37330</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Sun, 11 Jul 2010 21:50:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-37330</guid>
		<description>Lionel,

I agree that we don&#039;t want many (any) bi-directional associations when using the domain model pattern. Don&#039;t take the guidance given in this article as being complete - it is here to illustrate a very specific part of a more comprehensive set of techniques.

Also, see my more recent posts talking about how the domain model pattern shouldn&#039;t necessarily be used for all &quot;business logic&quot; and definitely not for the purposes of all persistence.

Kind regards.</description>
		<content:encoded><![CDATA[<p>Lionel,</p>
<p>I agree that we don&#8217;t want many (any) bi-directional associations when using the domain model pattern. Don&#8217;t take the guidance given in this article as being complete &#8211; it is here to illustrate a very specific part of a more comprehensive set of techniques.</p>
<p>Also, see my more recent posts talking about how the domain model pattern shouldn&#8217;t necessarily be used for all &#8220;business logic&#8221; and definitely not for the purposes of all persistence.</p>
<p>Kind regards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lionel Orellana</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-37328</link>
		<dc:creator>Lionel Orellana</dc:creator>
		<pubDate>Sat, 10 Jul 2010 00:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-37328</guid>
		<description>Hi Udi,

I&#039;ve gone through previous comments and couldn&#039;t see the point of bi-directional associations being raised directly. Your approach will create a lot more bi-directional associations than are otherwise needed. I don&#039;t think I&#039;m taking Evans too literally when I say bi-directional associations are best avoided. From the DDD bible:

&quot;In real life, there are lots of many-to-many associations, and a great number are naturally bidirectional. The same tends to be true of early forms of a model as we brainstorm and explore the domain. But these general associations complicate implementation and maintenance. Furthermore, they communicate very little about the nature of the
relationship&quot;.

Cheers,

Lionel.</description>
		<content:encoded><![CDATA[<p>Hi Udi,</p>
<p>I&#8217;ve gone through previous comments and couldn&#8217;t see the point of bi-directional associations being raised directly. Your approach will create a lot more bi-directional associations than are otherwise needed. I don&#8217;t think I&#8217;m taking Evans too literally when I say bi-directional associations are best avoided. From the DDD bible:</p>
<p>&#8220;In real life, there are lots of many-to-many associations, and a great number are naturally bidirectional. The same tends to be true of early forms of a model as we brainstorm and explore the domain. But these general associations complicate implementation and maintenance. Furthermore, they communicate very little about the nature of the<br />
relationship&#8221;.</p>
<p>Cheers,</p>
<p>Lionel.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-37213</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Tue, 27 Apr 2010 18:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-37213</guid>
		<description>Jørn,

First of all, aggregate roots (AR) are used on the command side of CQRS and not the query side, in which case theoretical reachability on the command side is less relevant.

Second, an AR is only relevant for scenarios where we&#039;re using a domain model - if the action is a simple insert operation, we can do that without using the domain model. Not all commands need to involve the same domain model.

I&#039;m pretty sure that that leaves you with more questions  - but the answers to those questions ultimately are project-specific. These patterns are to help you know which questions to ask - not to provide you with answers :-)</description>
		<content:encoded><![CDATA[<p>Jørn,</p>
<p>First of all, aggregate roots (AR) are used on the command side of CQRS and not the query side, in which case theoretical reachability on the command side is less relevant.</p>
<p>Second, an AR is only relevant for scenarios where we&#8217;re using a domain model &#8211; if the action is a simple insert operation, we can do that without using the domain model. Not all commands need to involve the same domain model.</p>
<p>I&#8217;m pretty sure that that leaves you with more questions  &#8211; but the answers to those questions ultimately are project-specific. These patterns are to help you know which questions to ask &#8211; not to provide you with answers <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jørn Wildt</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-37208</link>
		<dc:creator>Jørn Wildt</dc:creator>
		<pubDate>Mon, 26 Apr 2010 20:36:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-37208</guid>
		<description>Hi Udi

There&#039;s a thing that bothers me here. Others have mentioned it already: the size of the collection. Not only the initial collection - but the complete object graph that results from this line of thinking.

Let&#039;s assume we have a Website with blogs with posts with comments. Following the above principle, we add blogs through websites, posts through blogs, and comments through posts.

This means the root object, the Website, ends up containing a massive object graph where all possible content items on the website are reachable from the Website root. Is this really the intention?

It also makes it difficult to implement a content plugin structure since the Website has to know all possible content types at compile time in order to create the AddBlog, AddArticle, AddPhoto, AddUser etc. methods. This is probably not your intention, so what am I missing?

/Jørn</description>
		<content:encoded><![CDATA[<p>Hi Udi</p>
<p>There&#8217;s a thing that bothers me here. Others have mentioned it already: the size of the collection. Not only the initial collection &#8211; but the complete object graph that results from this line of thinking.</p>
<p>Let&#8217;s assume we have a Website with blogs with posts with comments. Following the above principle, we add blogs through websites, posts through blogs, and comments through posts.</p>
<p>This means the root object, the Website, ends up containing a massive object graph where all possible content items on the website are reachable from the Website root. Is this really the intention?</p>
<p>It also makes it difficult to implement a content plugin structure since the Website has to know all possible content types at compile time in order to create the AddBlog, AddArticle, AddPhoto, AddUser etc. methods. This is probably not your intention, so what am I missing?</p>
<p>/Jørn</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-37204</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Sat, 24 Apr 2010 11:14:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-37204</guid>
		<description>Ryzam,

Well, an existing customer may be an Aggregate Root for certain use cases in a given bounded context.</description>
		<content:encoded><![CDATA[<p>Ryzam,</p>
<p>Well, an existing customer may be an Aggregate Root for certain use cases in a given bounded context.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryzam</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-37203</link>
		<dc:creator>ryzam</dc:creator>
		<pubDate>Fri, 23 Apr 2010 23:21:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-37203</guid>
		<description>Hi Udi, your case is for newly customer, but how about existing customer. For me an existing customer can be right candidate to act as an AggregateRoot.

From general perspective, I see role archetype (peter coad) by default can be an AggregateRoot</description>
		<content:encoded><![CDATA[<p>Hi Udi, your case is for newly customer, but how about existing customer. For me an existing customer can be right candidate to act as an AggregateRoot.</p>
<p>From general perspective, I see role archetype (peter coad) by default can be an AggregateRoot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Strengthening your domain: Aggregate Construction - Jimmy Bogard - Los Techies : Blogs about software and anything tech!</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-37047</link>
		<dc:creator>Strengthening your domain: Aggregate Construction - Jimmy Bogard - Los Techies : Blogs about software and anything tech!</dc:creator>
		<pubDate>Wed, 24 Feb 2010 04:12:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-37047</guid>
		<description>[...] Through existing aggregate roots [...]</description>
		<content:encoded><![CDATA[<p>[...] Through existing aggregate roots [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-37033</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Thu, 18 Feb 2010 19:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-37033</guid>
		<description>Hi Udi,

I really like the idea of persistence by reachability. However, I&#039;m trying to implement this using NHibernate and I&#039;ve run into a problem with many to many relationships. How do you avoid loading up the entire collection when adding to it?

Thanks,
Jon</description>
		<content:encoded><![CDATA[<p>Hi Udi,</p>
<p>I really like the idea of persistence by reachability. However, I&#8217;m trying to implement this using NHibernate and I&#8217;ve run into a problem with many to many relationships. How do you avoid loading up the entire collection when adding to it?</p>
<p>Thanks,<br />
Jon</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Dingwall &#187; Life inside an Aggregate Root, part 2</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36794</link>
		<dc:creator>Richard Dingwall &#187; Life inside an Aggregate Root, part 2</dc:creator>
		<pubDate>Tue, 13 Oct 2009 18:31:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36794</guid>
		<description>[...] The new keyword is a bit of a smell here &#8212; as Udi Dahan recently stated in a blog post, customers don&#8217;t just appear out of thin air. Let&#8217;s flip it [...]</description>
		<content:encoded><![CDATA[<p>[...] The new keyword is a bit of a smell here &#8212; as Udi Dahan recently stated in a blog post, customers don&#8217;t just appear out of thin air. Let&#8217;s flip it [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36769</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Thu, 08 Oct 2009 15:15:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36769</guid>
		<description>Well Mike,

Then we can agree to disagree :)</description>
		<content:encoded><![CDATA[<p>Well Mike,</p>
<p>Then we can agree to disagree <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Scott</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36768</link>
		<dc:creator>Mike Scott</dc:creator>
		<pubDate>Thu, 08 Oct 2009 11:35:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36768</guid>
		<description>Hi Udi,

&quot;Would a unit test that mocks out the persistence layer give us much more confidence in the correctness of the code?&quot;

Yes, I believe it would. I think the service code should be unit-tested as well, even though it&#039;s simple. Any breaking changes will be detected in seconds, rather than waiting for them to fail in the integration tests and be more difficult to track down later.

If you take your argument to its logical conclusion, we could do away with unit tests altogether and rely solely on automated integration testing, could we not?

There&#039;s also the issue of using unit testing - or better to say specifying - first in order to create more expressive interfaces.</description>
		<content:encoded><![CDATA[<p>Hi Udi,</p>
<p>&#8220;Would a unit test that mocks out the persistence layer give us much more confidence in the correctness of the code?&#8221;</p>
<p>Yes, I believe it would. I think the service code should be unit-tested as well, even though it&#8217;s simple. Any breaking changes will be detected in seconds, rather than waiting for them to fail in the integration tests and be more difficult to track down later.</p>
<p>If you take your argument to its logical conclusion, we could do away with unit tests altogether and rely solely on automated integration testing, could we not?</p>
<p>There&#8217;s also the issue of using unit testing &#8211; or better to say specifying &#8211; first in order to create more expressive interfaces.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36760</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Sun, 04 Oct 2009 08:51:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36760</guid>
		<description>Mike,

You bring up the point exactly:

&quot;It has to work with the persistence layer as well as calling into the domain&quot;

Would a unit test that mocks out the persistence layer give us much more confidence in the correctness of the code? So much so that we didn&#039;t need the integration test? And if we do go and put an integration test in place, what incremental value does the unit test provide? Does it, in essence, assert that the code is implemented the way it&#039;s implemented?

Hope that makes sense.</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>You bring up the point exactly:</p>
<p>&#8220;It has to work with the persistence layer as well as calling into the domain&#8221;</p>
<p>Would a unit test that mocks out the persistence layer give us much more confidence in the correctness of the code? So much so that we didn&#8217;t need the integration test? And if we do go and put an integration test in place, what incremental value does the unit test provide? Does it, in essence, assert that the code is implemented the way it&#8217;s implemented?</p>
<p>Hope that makes sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36759</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Sun, 04 Oct 2009 08:48:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36759</guid>
		<description>Jørn,

Check out this link as well:

http://www.udidahan.com/2008/02/15/from-crud-to-domain-driven-fluency/</description>
		<content:encoded><![CDATA[<p>Jørn,</p>
<p>Check out this link as well:</p>
<p><a href="http://www.udidahan.com/2008/02/15/from-crud-to-domain-driven-fluency/" rel="nofollow">http://www.udidahan.com/2008/02/15/from-crud-to-domain-driven-fluency/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Scott</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36750</link>
		<dc:creator>Mike Scott</dc:creator>
		<pubDate>Tue, 29 Sep 2009 14:44:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36750</guid>
		<description>Udi

I understand that the service layer only makes a single call into the domain layer, but I&#039;m still not convinced that it&#039;s not doing enough orchestrating that it doesn&#039;t need unit testing. It has to work with the persistence layer as well as calling into the domain.

However, I do see your pont that if you have NHibernate code creating a session and a transaction in the session layer, that you could just forego abstracting your persistence, ignore unit testing and rely on integration tests.

Is this what you&#039;re advocating?</description>
		<content:encoded><![CDATA[<p>Udi</p>
<p>I understand that the service layer only makes a single call into the domain layer, but I&#8217;m still not convinced that it&#8217;s not doing enough orchestrating that it doesn&#8217;t need unit testing. It has to work with the persistence layer as well as calling into the domain.</p>
<p>However, I do see your pont that if you have NHibernate code creating a session and a transaction in the session layer, that you could just forego abstracting your persistence, ignore unit testing and rely on integration tests.</p>
<p>Is this what you&#8217;re advocating?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jørn Wildt</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36742</link>
		<dc:creator>Jørn Wildt</dc:creator>
		<pubDate>Fri, 25 Sep 2009 18:25:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36742</guid>
		<description>Udi, is it this your are talking about: http://www.udidahan.com/2007/10/26/teched-speaking-about-high-performance-persistent-domain-models/ when you say High Performance Domain Models presentation?

The links on that page are not alive anymore :-(

Can it be found elsewhere?</description>
		<content:encoded><![CDATA[<p>Udi, is it this your are talking about: <a href="http://www.udidahan.com/2007/10/26/teched-speaking-about-high-performance-persistent-domain-models/" rel="nofollow">http://www.udidahan.com/2007/10/26/teched-speaking-about-high-performance-persistent-domain-models/</a> when you say High Performance Domain Models presentation?</p>
<p>The links on that page are not alive anymore <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p>Can it be found elsewhere?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36741</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Thu, 24 Sep 2009 20:26:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36741</guid>
		<description>Mike,

The service layer shouldn&#039;t orchestrate - after getting a domain object or two, it calls a single method on one of them, that&#039;s it.

See my High Performance Domain Models presentation.</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>The service layer shouldn&#8217;t orchestrate &#8211; after getting a domain object or two, it calls a single method on one of them, that&#8217;s it.</p>
<p>See my High Performance Domain Models presentation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Scott</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36740</link>
		<dc:creator>Mike Scott</dc:creator>
		<pubDate>Thu, 24 Sep 2009 15:53:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36740</guid>
		<description>Hi Udi

It makes sense to test the domain model, of course, but it also makes sense to test the service layer to make sure it is orchestrating things correctly, no?</description>
		<content:encoded><![CDATA[<p>Hi Udi</p>
<p>It makes sense to test the domain model, of course, but it also makes sense to test the service layer to make sure it is orchestrating things correctly, no?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36737</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Mon, 21 Sep 2009 18:21:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36737</guid>
		<description>Mike,

The only code that depends on the ORM is the service layer. The domain model doesn&#039;t depend on anything other than itself - and it&#039;s the thing you&#039;ll be unit testing.

Does that make sense?</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>The only code that depends on the ORM is the service layer. The domain model doesn&#8217;t depend on anything other than itself &#8211; and it&#8217;s the thing you&#8217;ll be unit testing.</p>
<p>Does that make sense?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Scott</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36733</link>
		<dc:creator>Mike Scott</dc:creator>
		<pubDate>Sun, 20 Sep 2009 21:29:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36733</guid>
		<description>Sure, understand perfectly. But that leads to the next question ;)

Unit testing! How do you unit test the code that depends on the ORM? Do you abstract it?</description>
		<content:encoded><![CDATA[<p>Sure, understand perfectly. But that leads to the next question <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Unit testing! How do you unit test the code that depends on the ORM? Do you abstract it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36731</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Sun, 20 Sep 2009 05:47:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36731</guid>
		<description>Mike,

The repository in this case would need to be nothing more than a regular ORM that eagerly fetched the cart object  (if there was one) along with the user object. You don&#039;t need a custom repository for this.

The same thing goes for &quot;persistence by reachability&quot;, since the user object gets dirty, the ORM knows to persist it and the objects connected to it.

Hope that makes sense.</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>The repository in this case would need to be nothing more than a regular ORM that eagerly fetched the cart object  (if there was one) along with the user object. You don&#8217;t need a custom repository for this.</p>
<p>The same thing goes for &#8220;persistence by reachability&#8221;, since the user object gets dirty, the ORM knows to persist it and the objects connected to it.</p>
<p>Hope that makes sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Scott</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36730</link>
		<dc:creator>Mike Scott</dc:creator>
		<pubDate>Sun, 20 Sep 2009 00:45:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36730</guid>
		<description>Hi Udi

So if I&#039;m following you correctly, the user would be the aggregate root and the user repository would built the aggregate, assigning the cart if one existed already or leaving it null if not.

Then, in the user class&#039; domain logic, there would be code to create a new cart if it was null and this would be persisted by reachability?

If so, I can see that the code to deal with the cart is in the repository if one exists, and in the domain object if not. The usual way of handling this would be to have the load/check and creation together in the same piece of code, though your suggestion seems reasonable :-)</description>
		<content:encoded><![CDATA[<p>Hi Udi</p>
<p>So if I&#8217;m following you correctly, the user would be the aggregate root and the user repository would built the aggregate, assigning the cart if one existed already or leaving it null if not.</p>
<p>Then, in the user class&#8217; domain logic, there would be code to create a new cart if it was null and this would be persisted by reachability?</p>
<p>If so, I can see that the code to deal with the cart is in the repository if one exists, and in the domain object if not. The usual way of handling this would be to have the load/check and creation together in the same piece of code, though your suggestion seems reasonable <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-2/#comment-36722</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Thu, 17 Sep 2009 17:36:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36722</guid>
		<description>Mike,

The user object would have a reference to its cart object - check if its null, if so, create a new one, set the reference. The ORM would do the dirty tracking on the user object and know to persist the new cart / the modified old cart.

Does that answer your question?</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>The user object would have a reference to its cart object &#8211; check if its null, if so, create a new one, set the reference. The ORM would do the dirty tracking on the user object and know to persist the new cart / the modified old cart.</p>
<p>Does that answer your question?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Scott</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-1/#comment-36714</link>
		<dc:creator>Mike Scott</dc:creator>
		<pubDate>Wed, 16 Sep 2009 15:23:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36714</guid>
		<description>Udi,

Regarding #49, could you expand on how you&#039;d implement user.AddItemToCartForProgram(program, item, quantity)?

Gilligan says he needs to check if a cart exists and create one if not. Where and how would this check be done? It seems to be cascading the lookup. In your original example, the service layer asks the ORM/repository to get a referrer. This is cool in the service layer, but in AddItemToCartForProgram, the domain object would have to do that for the cart, no?

I&#039;d love to see your general solution to this type of behaviour :-)</description>
		<content:encoded><![CDATA[<p>Udi,</p>
<p>Regarding #49, could you expand on how you&#8217;d implement user.AddItemToCartForProgram(program, item, quantity)?</p>
<p>Gilligan says he needs to check if a cart exists and create one if not. Where and how would this check be done? It seems to be cascading the lookup. In your original example, the service layer asks the ORM/repository to get a referrer. This is cool in the service layer, but in AddItemToCartForProgram, the domain object would have to do that for the cart, no?</p>
<p>I&#8217;d love to see your general solution to this type of behaviour <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: udidahan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-1/#comment-36665</link>
		<dc:creator>udidahan</dc:creator>
		<pubDate>Sat, 05 Sep 2009 14:06:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36665</guid>
		<description>Gilligan,

Could you not do:

user.AddItemToCartForProgram(program, item, quantity);</description>
		<content:encoded><![CDATA[<p>Gilligan,</p>
<p>Could you not do:</p>
<p>user.AddItemToCartForProgram(program, item, quantity);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gilligan</title>
		<link>http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/comment-page-1/#comment-36663</link>
		<dc:creator>Gilligan</dc:creator>
		<pubDate>Fri, 04 Sep 2009 11:09:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.udidahan.com/?p=1042#comment-36663</guid>
		<description>I think my situation may not be appropriate domain driven behavior. 
It is more like this: a cart&#039;s identity is determined by two properties:  the current ordering program and the current user. So I will first get the program, then call a method program.GetCartForUser(user). This method will either create a new cart or retrieve an existing one. Then I will call cart.AddItem(item, quantity).</description>
		<content:encoded><![CDATA[<p>I think my situation may not be appropriate domain driven behavior.<br />
It is more like this: a cart&#8217;s identity is determined by two properties:  the current ordering program and the current user. So I will first get the program, then call a method program.GetCartForUser(user). This method will either create a new cart or retrieve an existing one. Then I will call cart.AddItem(item, quantity).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

