<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Billy McCafferty - All Comments</title><link>http://devlicio.us/blogs/billy_mccafferty/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>re: Bridging the Communities</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2008/01/10/bridging-the-communities.aspx#55881</link><pubDate>Fri, 12 Mar 2010 00:11:24 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55881</guid><dc:creator>Neo</dc:creator><description>&lt;p&gt;&amp;lt;a href= &lt;a rel="nofollow" target="_new" href="http://sharontateautop"&gt;http://sharontateautop&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55881" width="1" height="1"&gt;</description></item><item><title>re: Better Application Services and CQS using S#arp Architecture 1.0 Q3 2009</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/05/better-application-services-and-cqs-with-s-arp-architecture-1-0-q3-2009.aspx#55875</link><pubDate>Thu, 11 Mar 2010 22:01:17 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55875</guid><dc:creator>Chris F</dc:creator><description>&lt;p&gt;This is fantastic. I&amp;#39;ve been using S#arp Arch on a corporate back-end system for a year, and have had to do some of these changes myself. However, the CQS stuff with the SPs via NHibernate is pretty awesome, as is the acknowledgment for better DTOs integration.&lt;/p&gt;
&lt;p&gt;Great job.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55875" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55860</link><pubDate>Thu, 11 Mar 2010 13:01:28 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55860</guid><dc:creator>k</dc:creator><description>&lt;p&gt;k&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55860" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55801</link><pubDate>Tue, 09 Mar 2010 20:10:24 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55801</guid><dc:creator>Billy McCafferty</dc:creator><description>&lt;p&gt;Exactly! ;)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55801" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55798</link><pubDate>Tue, 09 Mar 2010 17:25:30 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55798</guid><dc:creator>corey coogan</dc:creator><description>&lt;p&gt;So as usual, it depends.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55798" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55793</link><pubDate>Tue, 09 Mar 2010 16:32:11 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55793</guid><dc:creator>Billy McCafferty</dc:creator><description>&lt;p&gt;Great discussion here!&lt;/p&gt;
&lt;p&gt;@Joe,&lt;/p&gt;
&lt;p&gt;After considering it further, and in light of well written arguments to this effect, I moved repository interfaces back to .Core for domain services to consume.&lt;/p&gt;
&lt;p&gt;Repositories need to be able to return reporting objects (as DTOs), which flatten the domain model. &amp;nbsp;If not, then you may end up traversing an immense amount of the domain model to simply show a few columns on a listing page. &amp;nbsp;If you allow a repository to return a DTO to encapsulate the reporting information, then this can reduce potentially hundreds - if not thousands - of queries, into one.&lt;/p&gt;
&lt;p&gt;@Martin,&lt;/p&gt;
&lt;p&gt;Terrifc explanation!! &amp;nbsp;In light of the way you describe, the DTOs in the domain layer could be called &amp;quot;QueryDtos&amp;quot; to better represent exactly why they exist.&lt;/p&gt;
&lt;p&gt;@James Broome,&lt;/p&gt;
&lt;p&gt;These are great arguments that have me thinking. &amp;nbsp;My gut reaction is that application services should not be platform-specific...or at least not know that they are. &amp;nbsp;In other words, I believe that application services are *ideally* platform agnostic. &amp;nbsp;With that said, there&amp;#39;s a difference between what&amp;#39;s ideal, what&amp;#39;s practical, and what the expectations are for the front-end platform to differ. &amp;nbsp;E.g., if it&amp;#39;s known from the get-go that multiple front ends will be communicating to the application services (ASP.NET, ASP.NET MVC, WCF, RESTful services), then application services should only expose objects which are platform agnostic and easily serializable with likely no direct exposure of the domain layer itself. &amp;nbsp;On the other hand, if you&amp;#39;re creating a CMS which inherently deals with *how* information is displayed, not just *what* information is to be displayed, then objects will inevitably carry such information all the way up through the layers from the repositories. &amp;nbsp;So I can see complete validation of your arguments, but in context of the needs of the application. &amp;nbsp;This is one of the immense challenges of creating an application framework (S#arp) which is opinionated enough to get people going very quickly, without being too preferential to a particular application type.&lt;/p&gt;
&lt;p&gt;@Peter,&lt;/p&gt;
&lt;p&gt;I agree that it&amp;#39;s quite likely that different consuming clients would require different information to be displayed. &amp;nbsp;With that said, the information would either be gathering directly within the consuming client (e.g., within controllers using repositories directly) or by adding additional application services which expose the needed information for consumers. &amp;nbsp;With smaller projects, I believe that controllers communicating directly with repositories is a great approach and keeps things simple. &amp;nbsp;With that said, if it&amp;#39;s expected that the application is going to get quite larger, I&amp;#39;ve shot myself in the foot a couple of times by not having a proper separation between the front-end (which includes the controllers) and the application services, or &amp;quot;surface area,&amp;quot; of the application.&lt;/p&gt;
&lt;p&gt;@corey coogan,&lt;/p&gt;
&lt;p&gt;I can see valid arguments for having domain services interact with repository interfaces. &amp;nbsp;But as a rule, I find that the more objects in the domain layer which interact directly with repositry interfaces, the harder it is to maintain and keep a clean separation of concerns. &amp;nbsp;For S#arp 1.5, we&amp;#39;ve ended up keeping the repository interfaces in the .Core layer (mostly for upgrading concerns), but also to accommodate the needs of domain services which may need to interact with repositories and/or for simpler applications which do not require such austere separation measures.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55793" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55791</link><pubDate>Tue, 09 Mar 2010 16:02:26 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55791</guid><dc:creator>corey coogan</dc:creator><description>&lt;p&gt;Great post Billy. &amp;nbsp;Concerning your last point, specifically &amp;quot;Ideally, repositories would not be used by domain objects&amp;quot;, would you mind adding a little more here.&lt;/p&gt;
&lt;p&gt;I realize that when I&amp;#39;m using NHibernate, my app service can load up an aggregate root and interact with those behaviors. &amp;nbsp;Assuming I have lazy loading enabled, my object could typically go without accessing a repository interface.&lt;/p&gt;
&lt;p&gt;What about cases where my domain object has operations that may or may not need real time data? &amp;nbsp;How do you handle that? &amp;nbsp;Do you just handle this through lazy loaded objects and composition? &amp;nbsp;It&amp;#39;s often times very enticing to just have a repository for a case where you need check inventory or something like that.&lt;/p&gt;
&lt;p&gt;I had discussions with Vauhn on the DDD group the other week about this same thing. &amp;nbsp;I was defending the Repository interfaces in Core while he keeps them with his service layer, much like you are describing.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;cc&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55791" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55790</link><pubDate>Tue, 09 Mar 2010 15:45:23 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55790</guid><dc:creator>Peter</dc:creator><description>&lt;p&gt;To me, the ViewModel doesn&amp;#39;t make sense in the application services layer since &amp;quot;what should be displayed&amp;quot; may be different depending on the consuming client. &amp;nbsp;That&amp;#39;s not a concern I&amp;#39;d want the &amp;quot;surface area&amp;quot; of my application to have. &amp;nbsp;Rather, I&amp;#39;d have it concerned with the relevant information to accomplish some task. &amp;nbsp;This is a subtle difference. &amp;nbsp;We don&amp;#39;t want to say what _should_ be displayed in the view. &amp;nbsp;We want to provide a report on the state of the application to support the client in making decisions. &amp;nbsp;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55790" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55782</link><pubDate>Tue, 09 Mar 2010 10:36:15 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55782</guid><dc:creator>James Broome</dc:creator><description>&lt;p&gt;Billy, &lt;/p&gt;
&lt;p&gt;I disagree with the statement about view models, that they are solely describing &amp;#39;what&amp;#39; should be displayed and not &amp;#39;how&amp;#39;. I still believe that view models are totally presentation specific (as I stated in the Sharp Arch discussion that led to this post) and therefore should live with the Controllers - i.e. with another presentation layer, the controllers and view models would be replaced. I&amp;#39;d like to give some real world examples to back this up. &lt;/p&gt;
&lt;p&gt;1. On the Fancy Dress Outfitters project, we had a requirement to be able to &amp;quot;theme&amp;quot; parts of the site. This would be controlled in a content management system, however our CMS definitions and content items were treated as as domain objects just like any other entity - i.e. to build up a view you needed data from a product database and data from a CMS database. All this was bound to a &amp;nbsp;view model to build up the view. In this case, themeing was controlled via CSS files and utimately it was up to the application to translate the selected theme into the path for the CSS file. This file path was passed into the view to be rendered out in a &amp;lt;link&amp;gt; element in the HTML.&lt;/p&gt;
&lt;p&gt;2. On the same project (and every other web project I&amp;#39;ve worked on) we&amp;#39;ve added Google Analytics code to the web page. The Google Analytics account ID is stored in some form of configuation source (web.config, database etc) and so needs to be passed to the view in order to render the analytics javascript code. We pass through the analytics code to as part of the view model.&lt;/p&gt;
&lt;p&gt;3. All public web pages should specify meta data, page titles etc. This isn&amp;#39;t always an exact copy of other pieces of view data - e.g. meta descriptions could come from CMS sources, or extracts of page content etc. Again, this is all passed into the view via the view model.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m getting at is if we agree that a view should be as &amp;quot;dumb&amp;quot; as possible, and be given everything it needs to display, then there are numerous situations where a view model contains information on &amp;quot;how&amp;quot; something is being rendered, or more specifically in these examples, be tied in to a particular presentation context (an HTML page). If I was to build a WPF presentation layer on top of my application, then all the examples above would be redundant. This would mean either refactoring my view models to try and maintain all types of presentation specific properties, or accepting that view models are tied to a particular presentation layer (and therefore live with the controllers).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55782" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55763</link><pubDate>Mon, 08 Mar 2010 22:20:26 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55763</guid><dc:creator>Martin Aatmaa</dc:creator><description>&lt;p&gt;&amp;quot;If the repository interfaces are maintained in .ApplicationServices, then DTOs may be maintained in a cleanly separated library without worrying about the line between DTOs and domain objects being grayed. &amp;nbsp;But data interfaces (and DTOs) may be maintained in .Core if the team feels the simplification is warranted.&amp;quot;&lt;/p&gt;
&lt;p&gt;I have found it beneficial to make a distinction between two &amp;quot;types&amp;quot; of DTOs:&lt;/p&gt;
&lt;p&gt;1) DTOs that serve to decouple the Domain (.Core) and the View.&lt;/p&gt;
&lt;p&gt;2) DTOs that serve as a complement to the Domain (.Core) and represent flattened read-optimized views of the domain&lt;/p&gt;
&lt;p&gt;In the case of 1), these DTOs should be maintained either in the Controllers layer, or in the ApplicationServices layer (if more than one client is able to share the same DTO). These DTOs would be populated by automapping domain entities to and from the DTOs. These DTOs would not be known to the Domain layer (including the Repo interfaces in the Domain layer).&lt;/p&gt;
&lt;p&gt;In the case of 2) these DTO&amp;#39;s should be maintained in the Domain layer. They would be populated via Repos (whose interfaces live in the Domain layer), and can be consumed directly via the View/Client layers.&lt;/p&gt;
&lt;p&gt;The latter type of DTO is treading the CQRS territory. Looking forward to seeing that pattern set gain more traction, as I see a lot of simplification possible there.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55763" width="1" height="1"&gt;</description></item><item><title>dotNET News </title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55756</link><pubDate>Mon, 08 Mar 2010 16:55:20 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55756</guid><dc:creator>Cadred (dotNET)</dc:creator><description>&lt;p&gt;dotNET News&lt;/p&gt;
&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55756" width="1" height="1"&gt;</description></item><item><title>A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns - Billy McCafferty - Devlicio.us - Just the Tasty Bits</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55742</link><pubDate>Mon, 08 Mar 2010 02:57:47 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55742</guid><dc:creator>9eFish</dc:creator><description>&lt;p&gt;9efish.感谢你的文章 - Trackback from 9eFish&lt;/p&gt;
&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55742" width="1" height="1"&gt;</description></item><item><title>S#arp Architecture in 2010</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/05/better-application-services-and-cqs-with-s-arp-architecture-1-0-q3-2009.aspx#55731</link><pubDate>Sun, 07 Mar 2010 22:41:28 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55731</guid><dc:creator>Alec Whittington</dc:creator><description>&lt;p&gt;So it has been rather quiet on this blog for quite sometime. I could give you the same old excuses that&lt;/p&gt;
&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55731" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55687</link><pubDate>Sun, 07 Mar 2010 00:47:04 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55687</guid><dc:creator>Joe Wilson</dc:creator><description>&lt;p&gt;I nodded in agreement the whole way through.&lt;/p&gt;
&lt;p&gt;My personal preference is view models that don&amp;#39;t reference to the domain model. &amp;nbsp;You&amp;#39;re right to point out the overlap and duplication this causes, but I see them as separate concerns and easily translated with AutoMapper in the application services layer. &amp;nbsp;One is the internal application model and the other is the external usage in the UI layer.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m also glad to see the new emphasis on the application services layer. &amp;nbsp;I like keeping my view models in that assembly. &amp;nbsp;The consuming UI has to have a reference to that assembly anyway.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m still digesting the idea of repository interfaces in the application services project instead of core. &amp;nbsp;I haven&amp;#39;t run into the DTO problem you describe, but my repos return domain entities, not DTOs, and I haven&amp;#39;t needed to separate out DTOs into an isolated assembly yet. &amp;nbsp;If I needed WCF integration, I would decorate my view models and app services with WCF attributes. &amp;nbsp;But in my mind, view models are just DTOs on the way to or from a view in the UI.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55687" width="1" height="1"&gt;</description></item><item><title>re: A Few Thoughts on DDD, DTOs, View Models, Repositories and Separation of Concerns</title><link>http://devlicio.us/blogs/billy_mccafferty/archive/2010/03/06/a-few-thoughts-on-ddd-dtos-view-models-cqs-repositories-and-separation-of-concerns.aspx#55680</link><pubDate>Sat, 06 Mar 2010 21:33:59 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55680</guid><dc:creator>Billy McCafferty</dc:creator><description>&lt;p&gt;Fair enough...I removed &amp;quot;CQS from the post title. ;)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55680" width="1" height="1"&gt;</description></item></channel></rss>