<?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: Favor query objects over repositories</title>
	<atom:link href="http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Sun, 19 May 2013 03:22:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: RyanVice</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5634</link>
		<dc:creator>RyanVice</dc:creator>
		<pubDate>Fri, 08 Mar 2013 18:03:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5634</guid>
		<description>If it&#039;s one query per action then queries don&#039;t represent cross cutting concerns and you might want to consider injecting an abstract query factory instead so that you can lazy instantiate your query objects. But as always it depends on the situation so just another thing to consider in your design.</description>
		<content:encoded><![CDATA[<p>If it&#8217;s one query per action then queries don&#8217;t represent cross cutting concerns and you might want to consider injecting an abstract query factory instead so that you can lazy instantiate your query objects. But as always it depends on the situation so just another thing to consider in your design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RyanVice</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5633</link>
		<dc:creator>RyanVice</dc:creator>
		<pubDate>Fri, 08 Mar 2013 17:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5633</guid>
		<description>Morten,

I know your question was for Jimmy but the way that we have tackled this on my projects is by using a View Model (UX) or RequestResponse (Web Service) approach which means that each action would return a DTO (View Model or Response). Then you have your query object  encapsulate all the querying logic needed to get the data needed by the DTO that is returned from your action method. We actually use stored procedures for this a lot of the time as it&#039;s easier write complex queries for most developers in a SP than using an ORM API. This allows you to maintain a thin controller but still have good code organization. To make things easier use Auto-Mapper to implement the Entity Translation pattern in the Query Object to move data out of your entities an into the DTO.</description>
		<content:encoded><![CDATA[<p>Morten,</p>
<p>I know your question was for Jimmy but the way that we have tackled this on my projects is by using a View Model (UX) or RequestResponse (Web Service) approach which means that each action would return a DTO (View Model or Response). Then you have your query object  encapsulate all the querying logic needed to get the data needed by the DTO that is returned from your action method. We actually use stored procedures for this a lot of the time as it&#8217;s easier write complex queries for most developers in a SP than using an ORM API. This allows you to maintain a thin controller but still have good code organization. To make things easier use Auto-Mapper to implement the Entity Translation pattern in the Query Object to move data out of your entities an into the DTO.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathieson Sterling</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5614</link>
		<dc:creator>Mathieson Sterling</dc:creator>
		<pubDate>Tue, 05 Mar 2013 19:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5614</guid>
		<description>While I don&#039;t agree the repository pattern doesn&#039;t provide value even in simple cases, you can easily use either query objects of specification patterns with your repository to get the same benefits you have here, and vastly reduce the amount of non-generic code you have to write.

Simply have your IRepository base interface have a method of GetBySpecification (or if you want, GetByQueryObject).  Pass in a Specification - you now have an extensible query capability without littering repository code all over controllers and other objects.  In addition like your query objects you have reusable components to create more complex queries.</description>
		<content:encoded><![CDATA[<p>While I don&#8217;t agree the repository pattern doesn&#8217;t provide value even in simple cases, you can easily use either query objects of specification patterns with your repository to get the same benefits you have here, and vastly reduce the amount of non-generic code you have to write.</p>
<p>Simply have your IRepository base interface have a method of GetBySpecification (or if you want, GetByQueryObject).  Pass in a Specification &#8211; you now have an extensible query capability without littering repository code all over controllers and other objects.  In addition like your query objects you have reusable components to create more complex queries.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jbogard</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5363</link>
		<dc:creator>jbogard</dc:creator>
		<pubDate>Thu, 29 Nov 2012 13:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5363</guid>
		<description>There is something missing there, I&#039;ll get that fixed.</description>
		<content:encoded><![CDATA[<p>There is something missing there, I&#8217;ll get that fixed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matteo</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5362</link>
		<dc:creator>Matteo</dc:creator>
		<pubDate>Thu, 29 Nov 2012 12:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5362</guid>
		<description>Is it just me or there is code missing between &quot;to suggest that this&quot; and &quot;Is not maintainable&quot;?
It&#039;s not the first post I find with missing code or paragraphs.</description>
		<content:encoded><![CDATA[<p>Is it just me or there is code missing between &#8220;to suggest that this&#8221; and &#8220;Is not maintainable&#8221;?<br />
It&#8217;s not the first post I find with missing code or paragraphs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morten Jacobsen</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5328</link>
		<dc:creator>Morten Jacobsen</dc:creator>
		<pubDate>Fri, 16 Nov 2012 20:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5328</guid>
		<description>I really like this approach, since I too find it hard conceptually to wade through a large repository containing lots of query methods..

My question would be this: You mention that you would generally restrict controllers to one query object per controller. Does that mean that your controller would project your domain classes to some kind of DTO that contains the data or do you prefer to return the entities directly?


What if you need to fetch multiple types of data, like blog posts and maybe a list of all blog tags? Would you then have separate controllers for each of these queries with one query object per controller or would you have one controller with a query object that fetches both lists?</description>
		<content:encoded><![CDATA[<p>I really like this approach, since I too find it hard conceptually to wade through a large repository containing lots of query methods..</p>
<p>My question would be this: You mention that you would generally restrict controllers to one query object per controller. Does that mean that your controller would project your domain classes to some kind of DTO that contains the data or do you prefer to return the entities directly?</p>
<p>What if you need to fetch multiple types of data, like blog posts and maybe a list of all blog tags? Would you then have separate controllers for each of these queries with one query object per controller or would you have one controller with a query object that fetches both lists?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jbogard</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5271</link>
		<dc:creator>jbogard</dc:creator>
		<pubDate>Wed, 07 Nov 2012 20:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5271</guid>
		<description>If there was an actual business need to be able to switch out underlying data providers, I would architect things differently.

Putting it a different way, I don&#039;t fabricate business needs, I work with the business to prove that needs exist. I don&#039;t like speculative architecture.

Remember, we&#039;re trying to match our code to the constraints we&#039;re working under. I don&#039;t have a constraint to have to be able to switch ORMs or database technologies.

However, if that need actually existed, I would provide seams for doing so, and isolate as I see appropriately. So for the context you described, I wholeheartedly agree with you!</description>
		<content:encoded><![CDATA[<p>If there was an actual business need to be able to switch out underlying data providers, I would architect things differently.</p>
<p>Putting it a different way, I don&#8217;t fabricate business needs, I work with the business to prove that needs exist. I don&#8217;t like speculative architecture.</p>
<p>Remember, we&#8217;re trying to match our code to the constraints we&#8217;re working under. I don&#8217;t have a constraint to have to be able to switch ORMs or database technologies.</p>
<p>However, if that need actually existed, I would provide seams for doing so, and isolate as I see appropriately. So for the context you described, I wholeheartedly agree with you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edward</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5270</link>
		<dc:creator>Edward</dc:creator>
		<pubDate>Wed, 07 Nov 2012 20:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5270</guid>
		<description>Jimmy, I don&#039;t really agree with you though. In my opinion, I think your style is tightly couplings Raven to your controllers. The question I have for you is, what&#039;s the level of effort in case you decided to use EF instead of Raven.</description>
		<content:encoded><![CDATA[<p>Jimmy, I don&#8217;t really agree with you though. In my opinion, I think your style is tightly couplings Raven to your controllers. The question I have for you is, what&#8217;s the level of effort in case you decided to use EF instead of Raven.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Testing with queries and repositories (a simple example) &#124; Jimmy Bogard&#039;s Blog</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5254</link>
		<dc:creator>Testing with queries and repositories (a simple example) &#124; Jimmy Bogard&#039;s Blog</dc:creator>
		<pubDate>Tue, 06 Nov 2012 14:53:16 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5254</guid>
		<description>[...] being much of a fan of the Repository pattern, or better yet, not a fan of applying it as a universal data access strategy, one question that [...]</description>
		<content:encoded><![CDATA[<p>[...] being much of a fan of the Repository pattern, or better yet, not a fan of applying it as a universal data access strategy, one question that [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Vice</title>
		<link>http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5252</link>
		<dc:creator>Ryan Vice</dc:creator>
		<pubDate>Tue, 06 Nov 2012 00:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/#comment-5252</guid>
		<description>Definitely prefer Query Object to Repository pattern. Query Object can take more code to create a simple CRUD operation than a good generic Repository Pattern implementation but Query Object really goes a long way for code organization and preventing controller bloat. We provide both on my current project so that developers can choose which approach they prefer and use our generic Repository to quickly grab low hanging fruit and then put the extra effort into building a Query object when they are dealing with more complex queries and want to get closer to the metal with the ORM.

That said, to me most Repository pattern implementations I&#039;ve seen are closer to a Transaction Script and in that context I&#039;d probably always prefer Query Object and not even bother providing a Repository pattern alternative. Transaction scripts just end up being a big, confusing, bloated interface on any decent complex project.</description>
		<content:encoded><![CDATA[<p>Definitely prefer Query Object to Repository pattern. Query Object can take more code to create a simple CRUD operation than a good generic Repository Pattern implementation but Query Object really goes a long way for code organization and preventing controller bloat. We provide both on my current project so that developers can choose which approach they prefer and use our generic Repository to quickly grab low hanging fruit and then put the extra effort into building a Query object when they are dealing with more complex queries and want to get closer to the metal with the ORM.</p>
<p>That said, to me most Repository pattern implementations I&#8217;ve seen are closer to a Transaction Script and in that context I&#8217;d probably always prefer Query Object and not even bother providing a Repository pattern alternative. Transaction scripts just end up being a big, confusing, bloated interface on any decent complex project.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
