<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wizards of Smart &#187; Tips</title>
	<atom:link href="http://wizardsofsmart.net/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://wizardsofsmart.net</link>
	<description>.NET Design Patterns</description>
	<lastBuildDate>Thu, 29 Jul 2010 16:40:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-beta2-14896</generator>
		<item>
		<title>IE9 Standards Support Poll</title>
		<link>http://wizardsofsmart.net/tips/ie9-standards-support-poll/</link>
		<comments>http://wizardsofsmart.net/tips/ie9-standards-support-poll/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 04:43:18 +0000</pubDate>
		<dc:creator>panesofglass</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://wizardsofsmart.net/?p=291</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<script type='text/javascript' language='javascript' charset='utf-8' src='http://s3.polldaddy.com/p/2333780.js'></script><noscript> <a href='http://answers.polldaddy.com/poll/2333780/' onclick="urchinTracker('/outgoing/answers.polldaddy.com/poll/2333780/?referer=');">View Poll</a></noscript>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/tips/ie9-standards-support-poll/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello Open Rasta</title>
		<link>http://wizardsofsmart.net/tips/hello-open-rasta/</link>
		<comments>http://wizardsofsmart.net/tips/hello-open-rasta/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 04:29:37 +0000</pubDate>
		<dc:creator>rookieone</dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://wizardsofsmart.net/uncategorized/hello-open-rasta/</guid>
		<description><![CDATA[So Ryan, the apostle of everything on the web, has been spreading the gospel of Open Rasta for months. Tonight I decided that finally, I should download and give this fantastical framework a shot. For an explanation on what OpenRasta is and is not, I shall direct you to their sites: Open Rasta Documentation Open [...]]]></description>
			<content:encoded><![CDATA[<p>So Ryan, the apostle of everything on the web, has been spreading the gospel of Open Rasta for months. Tonight I decided that finally, I should download and give this fantastical framework a shot.</p>
<p>For an explanation on what OpenRasta is and is not, I shall direct you to their sites:</p>
<ol>
<li><font color="#efefef"><a href="http://trac.caffeine-it.com/openrasta/wiki/Doc" onclick="urchinTracker('/outgoing/trac.caffeine-it.com/openrasta/wiki/Doc?referer=');">Open Rasta Documentation</a></font></li>
<li><font color="#efefef"><a href="http://www.ohloh.net/p/openrasta" onclick="urchinTracker('/outgoing/www.ohloh.net/p/openrasta?referer=');">Open Rasta Download Home</a></font></li>
</ol>
<p>What I am going to do is just describe my experience trying their framework for the first time.</p>
<p>I am a person that likes to learn by trying so I immediately jumped to the ‘creating your first OpenRasta website’ (<a href="http://svn.caffeine-it.com/openrasta/trunk/doc/content/Tutorials/Create-First-Site.html" onclick="urchinTracker('/outgoing/svn.caffeine-it.com/openrasta/trunk/doc/content/Tutorials/Create-First-Site.html?referer=');">here</a>). I have looked at some of Ryan’s code and have survived several conversations with Ryan over the framework. <img src='http://wizardsofsmart.net/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  I believe that is enough preparation for at least a simple tutorial.</p>
<p>Well I go to the modifying the web.config section and was left with a broken solution. Apparently from the time the tutorial was written and the time I downloaded the version 2.0.2039.312, the handlers and modules all moved to another assembly. I had a gut feeling it moved and when I talked to Ryan, he confirmed my suspicions. Supposedly he is going to try and update the tutorial.</p>
<p>In the meantime, just change ….&quot;OpenRasta.Web.OpenRastaHandler, OpenRasta&quot;</p>
<p>to… &quot;OpenRasta.Hosting.AspNet.OpenRastaHandler, OpenRasta.Hosting.AspNet&quot;</p>
<p>So change the assembly reference from the OpenRasta.dll to the OpenRasta.Hosting.AspNet.dll</p>
<p>I assume if you are reading this you have the skill set to modify said correction for the other references.</p>
<p>After that I breezed through the creation of the ‘Home’ resource and the ‘Home’ handler. No duh? Any programmer can make a couple of classes. <img src='http://wizardsofsmart.net/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I’m at the configuration section and I have to say, I love the fluent interface. Anyone who has talked to me in the past 6 months knows I love the pattern. It instantly makes any framework extremely approachable. </p>
<p>The tutorial has you making a manual configuration. I tried to find an auto configuration just using some intellisense with no luck. I will investigate this further. If I was going to use OpenRasta I would definitely want a convention based solution. Even with a nice fluent interface, I really don’t want to manually create all my mappings by hand. </p>
<p>But there is something to be said for simply creating a mapping like :</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ResourceSpace.Has</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    .ResourcesOfType&lt;Home&gt;()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    .AtUri(<span style="color: #006080">&quot;/home&quot;</span>)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    .HandledBy&lt;HomeHandler&gt;();</pre>
</p></div>
</div>
<p>
  <br />I ran the app expecting the 405 method error as the tutorial predicts.. and got an empty page. I was using FireFox, so I jumped over to IE and was then greeted by the 405 error. I assume FireFox is either handling the problem gracefully or I don’t have some settings setup to display these errors. /shrug</p>
<p>So then I created my ‘Get’ method on my HomeHandler. One of the things that did attract me to OpenRasta was the POCO handlers. I’ve grown to appreciate very clean code with some acceptable conventions. Just makes life easier. I can focus on the domain problem and not the intricacies of any given framework.</p>
<p>Most of this seemingly new re-invention of HTTP as ESB, REST, Atom.. etc is interesting in that its a reexamining of a technology we use all the time. I haven’t done web development in roughly 3 years. The majority of my experience is in smart client apps. That is just the way my career and projects played out for me. The websites I created were always very basic and probably crap if judged by web developer gurus.</p>
<p>Anyway.</p>
<p>We click links and magically we get a web page. We don’t really think much about it. Sort of like turning on a light switch or starting your car. We just expect things to work and don’t really worry about it. How many drivers can actually explain a combustion engine? </p>
<p>There is a lot going on in the background to make the web work. This new (new to me at least) area of development is leveraging the tech the way it was supposed to be used (if I am to believe the pioneers in this arena). A lot of this is a change of perspective. And with any change of perspective it can take awhile to make the transition.</p>
<p>After that side trip down my ramblings, we come back to me having a handler with a Get method. Now I have graduated to a 406 error (as expected by the tutorial).</p>
<p>I then created my view as the tutorial suggested. Now upon trying to fluently configure.. I ran into a snag. Again the tutorial is out dated (which is fine for an open source and still growing framework).</p>
<p>I had to add the “OpenRasta.Codecs.WebForms.dll” to the solution. </p>
<p>Also the fluent configuration suggested is…</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ResourceSpace.Has.ResourcesOfType&lt;Home&gt;()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        .AtUri(<span style="color: #006080">&quot;/home&quot;</span>)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        .HandledBy&lt;HomeHandler&gt;()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        .AndRendededByAspx(<span style="color: #006080">&quot;~/Views/HomeView.aspx&quot;</span>);</pre>
</p></div>
</div>
<p>But since the AndRendededByAspx is obselete, the code should now be:</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ResourceSpace.Has.ResourcesOfType&lt;Home&gt;()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                    .AtUri(<span style="color: #006080">&quot;/home&quot;</span>)</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                    .HandledBy&lt;HomeHandler&gt;()</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                    .RenderedByAspx(<span style="color: #006080">&quot;~/Views/HomeView.aspx&quot;</span>);</pre>
</p></div>
</div>
<p>I then continued the tutorial until I had my Home View that displayed my lovely welcome message.</p>
<p>Yay! I got my first Open Rasta page to work. <img src='http://wizardsofsmart.net/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Feel free to investigate my project at my Git Hub repository:</p>
<p><a title="http://github.com/RookieOne/OpenRastaExperiment/tree/TutorialCompletion" href="http://github.com/RookieOne/OpenRastaExperiment/tree/TutorialCompletion" onclick="urchinTracker('/outgoing/github.com/RookieOne/OpenRastaExperiment/tree/TutorialCompletion?referer=');">http://github.com/RookieOne/OpenRastaExperiment/tree/TutorialCompletion</a></p>
<p>I’m going to be continuing to change the master branch but the TutorialCompletion branch should remain unchanged.</p>
<p>SO check out OpenRasta and their (and my) tutorial. Its short and is a great window into viewing the web in a slightly different manner.</p>
<p>Thanks for your time!</p>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/tips/hello-open-rasta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YAGNI&#8211;Whose Definition of Simple?</title>
		<link>http://wizardsofsmart.net/patterns/yagni-whose-definition-of-simple/</link>
		<comments>http://wizardsofsmart.net/patterns/yagni-whose-definition-of-simple/#comments</comments>
		<pubDate>Tue, 12 May 2009 13:00:52 +0000</pubDate>
		<dc:creator>panesofglass</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[SOLID]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[YAGNI]]></category>

		<guid isPermaLink="false">http://wizardsofsmart.net/patterns/yagni-whose-definition-of-simple</guid>
		<description><![CDATA[I have read a lot about YAGNI lately, especially regarding TDD. The thing that keeps bugging me is the definition of &#8220;simple.&#8221; Who defines simple? For instance, wouldn&#8217;t static methods be simpler than building objects? You could then write more functionally. Or is that not simpler to you? If you follow command-query separation, wouldn&#8217;t building [...]]]></description>
			<content:encoded><![CDATA[<p>I have read a lot about <a class="zem_slink" title="You Ain't Gonna Need It" rel="wikipedia" href="http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/You_Ain_27t_Gonna_Need_It?referer=');">YAGNI</a> lately, especially regarding <a class="zem_slink" title="Test-driven development" rel="wikipedia" href="http://en.wikipedia.org/wiki/Test-driven_development" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/Test-driven_development?referer=');">TDD</a>. The thing that keeps bugging me is the definition of &#8220;simple.&#8221; Who defines simple? For instance, wouldn&#8217;t static methods be simpler than building objects? You could then write more functionally. Or is that not simpler to you? If you follow <a class="zem_slink" title="Command-query separation" rel="wikipedia" href="http://en.wikipedia.org/wiki/Command-query_separation" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/Command-query_separation?referer=');">command-query separation</a>, wouldn&#8217;t building everything as either pure functions or commands be simplest? JB and I have found this set of patterns immensely easy to create and test of late, especially in comparison to the ever-increasing-in-complexity procedural/OO code in place before.</p>
<p>So I guess my question is this: Is it really so bad to start with some basic patterns that will let you <a class="zem_slink" title="Code refactoring" rel="wikipedia" href="http://en.wikipedia.org/wiki/Code_refactoring" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/Code_refactoring?referer=');">refactor</a> more easily? I think the desire to make things as simple as possible&#8211;especially when you know you will need it&#8211;can be a waste of time and a good way of getting bad code into your source.</p>
<p>I know I will hear it from the Agile community that I just don&#8217;t get it, but I think I do. I really like starting simple and keeping things in nice, bite-sized testable chunks. And yes, I&#8217;m still learning. However, without a consistent and meaningful definition of &#8220;simple,&#8221; we&#8217;re likely to end up with a follow-up movement of making things complex for the sake of extensibility again.</p>
<p>So what do you think: is CQS too complex a starting point, or is it a nice, &#8220;simple,&#8221; and testable approach for YAGNI?</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=933e7d8e-8c97-4679-ad3a-421e33908d4a" alt="" /><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/patterns/yagni-whose-definition-of-simple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acase().for(patternType.FluentInterfaces).create()</title>
		<link>http://wizardsofsmart.net/patterns/acaseforpatterntypefluentinterfacescreate/</link>
		<comments>http://wizardsofsmart.net/patterns/acaseforpatterntypefluentinterfacescreate/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 21:53:05 +0000</pubDate>
		<dc:creator>rookieone</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Samples]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://wizardsofsmart.net/uncategorized/acaseforpatterntypefluentinterfacescreate</guid>
		<description><![CDATA[When I was first exposed to the idea of fluent interfaces my response was… big flipping deal. It wasn’t until I actively started using fluent interfaces in my code did I begin to see their power and elegance. What is a fluent interface? Here is the obligatory link to wikipedia In simple terms, its returning [...]]]></description>
			<content:encoded><![CDATA[<p>When I was first exposed to the idea of fluent interfaces my response was… big flipping deal.</p>
<p>It wasn’t until I actively started using fluent interfaces in my code did I begin to see their power and elegance.</p>
<p>What is a fluent interface? Here is the obligatory <a href="http://en.wikipedia.org/wiki/Fluent_interface" target="_blank" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/Fluent_interface?referer=');">link</a> to wikipedia <img src='http://wizardsofsmart.net/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </p>
<p>In simple terms, its returning a type instead of void in order to achieve method chaining.</p>
<p>The end goal of the method chaining is to provide a more readable interface and code.</p>
<p>First, does it break the Law of Demeter?</p>
<p>Law of Demeter doesn’t equal the number of periods. I am of the opinion fluent interfaces do not violate the Law of Demeter.</p>
<p>What is LoD? Another <a href="http://en.wikipedia.org/wiki/Law_Of_Demeter" target="_blank" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/Law_Of_Demeter?referer=');">link</a> to wiki and here is a <a href="http://stackoverflow.com/questions/67561/do-fluent-interfaces-violate-the-law-of-demeter" target="_blank" onclick="urchinTracker('/outgoing/stackoverflow.com/questions/67561/do-fluent-interfaces-violate-the-law-of-demeter?referer=');">link</a> to a stack overflow on this very subject! <img src='http://wizardsofsmart.net/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To me, Law of Demeter is about restricting communication between objects.</p>
<p>A common violation of LoD (imho) is the exposure of a list property on an object. I believe this serves as a good example of LoD as well as being an example on how to make a fluent interface. <img src='http://wizardsofsmart.net/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>A Person object has a name and a list of friends.</p>
<div class="csharpcode">
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> Person</pre>
<pre><span class="lnum">   2:  </span>    {</pre>
<pre class="alt"><span class="lnum">   3:  </span>        <span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }</pre>
<pre><span class="lnum">   4:  </span>        <span class="kwrd">public</span> List&lt;Person&gt; Friends { get; set; }</pre>
<pre class="alt"><span class="lnum">   5:  </span>&nbsp;</pre>
<pre><span class="lnum">   6:  </span>        <span class="kwrd">public</span> Person()</pre>
<pre class="alt"><span class="lnum">   7:  </span>        {</pre>
<pre><span class="lnum">   8:  </span>            Friends = <span class="kwrd">new</span> List&lt;Person&gt;();</pre>
<pre class="alt"><span class="lnum">   9:  </span>        }</pre>
<pre><span class="lnum">  10:  </span>    }</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<pre class="alt"></pre>
</div>
<p>I could then add friends by…</p>
<div class="csharpcode">&nbsp;</div>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>var roger = <span class="kwrd">new</span> Person{ Name=<span class="str">"Roger"</span> };</pre>
<pre><span class="lnum">   2:  </span>roger.Friends.Add(<span class="kwrd">new</span> Person { Name = <span class="str">"Eddie"</span> });</pre>
<pre class="alt"><span class="lnum">   3:  </span>roger.Friends.Add(<span class="kwrd">new</span> Person { Name = <span class="str">"Freddie"</span> });</pre>
<pre><span class="lnum">   4:  </span>roger.Friends.Add(<span class="kwrd">new</span> Person { Name = <span class="str">"Gordie"</span> });</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Now this is pretty typical, so what’s the problem?</p>
<p>Well my code knows WAY too much about Person. I know it has a list of friends and if they change that list to say a dictionary, I am hosed.</p>
<p>Not only that, but poor Person class… people can add friends to his collection without him every knowing. What if some additional logic needs to be done when adding a friend? </p>
<p>What if the person wants to record the birth date of every friend so they can send out birthday cards? Person is SOL.</p>
<p>As for Law of Demeter, my code is using the Person object to communicate through to the List&lt;Person&gt;. I am exposing my code to changes in Person.</p>
<p>Let’s change Person to eliminate this problem.</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> Person2</pre>
<pre><span class="lnum">   2:  </span>    {</pre>
<pre class="alt"><span class="lnum">   3:  </span>        <span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }</pre>
<pre><span class="lnum">   4:  </span>        <span class="kwrd">private</span> <span class="kwrd">readonly</span> List&lt;Person2&gt; _friends;</pre>
<pre class="alt"><span class="lnum">   5:  </span>&nbsp;</pre>
<pre><span class="lnum">   6:  </span>        <span class="kwrd">public</span> Person2()</pre>
<pre class="alt"><span class="lnum">   7:  </span>        {</pre>
<pre><span class="lnum">   8:  </span>            _friends = <span class="kwrd">new</span> List&lt;Person2&gt;();</pre>
<pre class="alt"><span class="lnum">   9:  </span>        }</pre>
<pre><span class="lnum">  10:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  11:  </span>        <span class="kwrd">public</span> <span class="kwrd">void</span> AddFriend(Person2 friend)</pre>
<pre><span class="lnum">  12:  </span>        {</pre>
<pre class="alt"><span class="lnum">  13:  </span>            _friends.Add(friend);</pre>
<pre><span class="lnum">  14:  </span>        }</pre>
<pre class="alt"><span class="lnum">  15:  </span>    }</pre>
</div>
<p><style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Now the only way to add a friend is through Person. Yippie!</p>
<p>&nbsp;</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>var roger2 = <span class="kwrd">new</span> Person2 {Name = <span class="str">"Roger"</span>};</pre>
<pre><span class="lnum">   2:  </span>roger2.AddFriend(<span class="kwrd">new</span> Person2 { Name = <span class="str">"Eddie"</span> });</pre>
<pre class="alt"><span class="lnum">   3:  </span>roger2.AddFriend(<span class="kwrd">new</span> Person2 { Name = <span class="str">"Freddie"</span> });</pre>
<pre><span class="lnum">   4:  </span>roger2.AddFriend(<span class="kwrd">new</span> Person2 { Name = <span class="str">"Gordie"</span> });</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>&nbsp;</p>
</p>
</p>
</p>
<p>If I wanted to make this a fluent interface all I would need to do is instead of returning void, return the Person class. </p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> Person3</pre>
<pre><span class="lnum">   2:  </span>    {</pre>
<pre class="alt"><span class="lnum">   3:  </span>        <span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }</pre>
<pre><span class="lnum">   4:  </span>        <span class="kwrd">private</span> <span class="kwrd">readonly</span> List&lt;Person3&gt; _friends;</pre>
<pre class="alt"><span class="lnum">   5:  </span>&nbsp;</pre>
<pre><span class="lnum">   6:  </span>        <span class="kwrd">public</span> Person3()</pre>
<pre class="alt"><span class="lnum">   7:  </span>        {</pre>
<pre><span class="lnum">   8:  </span>            _friends = <span class="kwrd">new</span> List&lt;Person3&gt;();</pre>
<pre class="alt"><span class="lnum">   9:  </span>        }</pre>
<pre><span class="lnum">  10:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  11:  </span>        <span class="kwrd">public</span> Person3 AddFriend(Person3 friend)</pre>
<pre><span class="lnum">  12:  </span>        {</pre>
<pre class="alt"><span class="lnum">  13:  </span>            _friends.Add(friend);</pre>
<pre><span class="lnum">  14:  </span>            <span class="kwrd">return</span> <span class="kwrd">this</span>;</pre>
<pre class="alt"><span class="lnum">  15:  </span>        }</pre>
<pre><span class="lnum">  16:  </span>    }</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Now I can do the same logic like…</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>var roger3 = <span class="kwrd">new</span> Person3 { Name = <span class="str">"Roger"</span> }</pre>
<pre><span class="lnum">   2:  </span>                            .AddFriend(<span class="kwrd">new</span> Person3 { Name = <span class="str">"Eddie"</span> })</pre>
<pre class="alt"><span class="lnum">   3:  </span>                            .AddFriend(<span class="kwrd">new</span> Person3 { Name = <span class="str">"Freddie"</span> })</pre>
<pre><span class="lnum">   4:  </span>                            .AddFriend(<span class="kwrd">new</span> Person3 { Name = <span class="str">"Gordie"</span> });</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>That is pretty cool, but fluent interfaces really shine with the builder pattern.</p>
<p>This time around I want to force construction of a person through a builder and have the builder use a fluent interface. Notice my Person’s constructor and fields are private. I embed the builder class within the Person class so the builder has access to the constructor and fields. In this manner only my builder class has access to constructing a person. My builder can now act as an anti-corruption layer for Person.</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> Person4</pre>
<pre><span class="lnum">   2:  </span>    {</pre>
<pre class="alt"><span class="lnum">   3:  </span>        <span class="kwrd">private</span> <span class="kwrd">string</span> _name;</pre>
<pre><span class="lnum">   4:  </span>        <span class="kwrd">private</span> List&lt;Person4&gt; _friends;</pre>
<pre class="alt"><span class="lnum">   5:  </span>&nbsp;</pre>
<pre><span class="lnum">   6:  </span>        <span class="kwrd">private</span> Person4()</pre>
<pre class="alt"><span class="lnum">   7:  </span>        {</pre>
<pre><span class="lnum">   8:  </span>            _friends = <span class="kwrd">new</span> List&lt;Person4&gt;();</pre>
<pre class="alt"><span class="lnum">   9:  </span>        }</pre>
<pre><span class="lnum">  10:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  11:  </span>        <span class="kwrd">public</span> Person4 AddFriend(Person4 friend)</pre>
<pre><span class="lnum">  12:  </span>        {</pre>
<pre class="alt"><span class="lnum">  13:  </span>            _friends.Add(friend);</pre>
<pre><span class="lnum">  14:  </span>            <span class="kwrd">return</span> <span class="kwrd">this</span>;</pre>
<pre class="alt"><span class="lnum">  15:  </span>        }</pre>
<pre><span class="lnum">  16:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  17:  </span>        <span class="kwrd">public</span> <span class="kwrd">static</span> PersonBuilder createAPerson()</pre>
<pre><span class="lnum">  18:  </span>        {</pre>
<pre class="alt"><span class="lnum">  19:  </span>            <span class="kwrd">return</span> <span class="kwrd">new</span> PersonBuilder();</pre>
<pre><span class="lnum">  20:  </span>        }</pre>
<pre class="alt"><span class="lnum">  21:  </span>&nbsp;</pre>
<pre><span class="lnum">  22:  </span>        <span class="kwrd">public</span> <span class="kwrd">class</span> PersonBuilder</pre>
<pre class="alt"><span class="lnum">  23:  </span>        {</pre>
<pre><span class="lnum">  24:  </span>            <span class="kwrd">private</span> Person4 _person;</pre>
<pre class="alt"><span class="lnum">  25:  </span>            <span class="kwrd">public</span> PersonBuilder()</pre>
<pre><span class="lnum">  26:  </span>            {</pre>
<pre class="alt"><span class="lnum">  27:  </span>                _person = <span class="kwrd">new</span> Person4();</pre>
<pre><span class="lnum">  28:  </span>            }</pre>
<pre class="alt"><span class="lnum">  29:  </span>&nbsp;</pre>
<pre><span class="lnum">  30:  </span>            <span class="kwrd">public</span> PersonBuilder named(<span class="kwrd">string</span> name)</pre>
<pre class="alt"><span class="lnum">  31:  </span>            {</pre>
<pre><span class="lnum">  32:  </span>                _person._name = name;</pre>
<pre class="alt"><span class="lnum">  33:  </span>                <span class="kwrd">return</span> <span class="kwrd">this</span>;</pre>
<pre><span class="lnum">  34:  </span>            }</pre>
<pre class="alt"><span class="lnum">  35:  </span>&nbsp;</pre>
<pre><span class="lnum">  36:  </span>            <span class="kwrd">public</span> PersonBuilder withFriend(Person4 friend)</pre>
<pre class="alt"><span class="lnum">  37:  </span>            {</pre>
<pre><span class="lnum">  38:  </span>                _person.AddFriend(friend);</pre>
<pre class="alt"><span class="lnum">  39:  </span>                <span class="kwrd">return</span> <span class="kwrd">this</span>;</pre>
<pre><span class="lnum">  40:  </span>            }</pre>
<pre class="alt"><span class="lnum">  41:  </span>&nbsp;</pre>
<pre><span class="lnum">  42:  </span>            <span class="kwrd">public</span> PersonBuilder withaFriendNamed(<span class="kwrd">string</span> name)</pre>
<pre class="alt"><span class="lnum">  43:  </span>            {</pre>
<pre><span class="lnum">  44:  </span>                var friend = createAPerson().named(name).finish();</pre>
<pre class="alt"><span class="lnum">  45:  </span>                _person.AddFriend(friend);</pre>
<pre><span class="lnum">  46:  </span>                <span class="kwrd">return</span> <span class="kwrd">this</span>;</pre>
<pre class="alt"><span class="lnum">  47:  </span>            }</pre>
<pre><span class="lnum">  48:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  49:  </span>            <span class="kwrd">public</span> Person4 finish()</pre>
<pre><span class="lnum">  50:  </span>            {</pre>
<pre class="alt"><span class="lnum">  51:  </span>                <span class="kwrd">return</span> _person;</pre>
<pre><span class="lnum">  52:  </span>            }</pre>
<pre class="alt"><span class="lnum">  53:  </span>        }</pre>
<pre><span class="lnum">  54:  </span>    }</pre>
</div>
<p><style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p>
<p>Now to create Roger and his friends I do..</p>
<div class="csharpcode">&nbsp;</div>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>var roger4 = Person4.createAPerson()</pre>
<pre><span class="lnum">   2:  </span>                    .named(<span class="str">"Roger"</span>)</pre>
<pre class="alt"><span class="lnum">   3:  </span>                    .withaFriendNamed(<span class="str">"Eddie"</span>)</pre>
<pre><span class="lnum">   4:  </span>                    .withaFriendNamed(<span class="str">"Freddie"</span>)</pre>
<pre class="alt"><span class="lnum">   5:  </span>                    .withaFriendNamed(<span class="str">"Gordie"</span>)</pre>
<pre><span class="lnum">   6:  </span>                    .finish();       </pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>It’s a simple example but maybe it sparked some ideas on how to use fluent interfaces to chain methods and make your code more approachable to people without Computer Science degrees. <img src='http://wizardsofsmart.net/wp/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>JB</p>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/patterns/acaseforpatterntypefluentinterfacescreate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch Updates and Deletes with LINQ to SQL</title>
		<link>http://wizardsofsmart.net/tips/batch-updates-and-deletes-with-linq-to-sql/</link>
		<comments>http://wizardsofsmart.net/tips/batch-updates-and-deletes-with-linq-to-sql/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 03:41:10 +0000</pubDate>
		<dc:creator>panesofglass</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Batch Processing]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://wizardsofsmart.net/?p=116</guid>
		<description><![CDATA[If you haven&#8217;t seen this already, you need to check it out. Terry Aney did an amazing job.]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t seen <a title="Batch Updates and Deletes with LINQ to SQL" href="http://www.aneyfamily.com/terryandann/post/2008/04/Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx" onclick="urchinTracker('/outgoing/www.aneyfamily.com/terryandann/post/2008/04/Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx?referer=');">this</a> already, you need to check it out. <a title="Terry Aney's Blog" href="http://www.aneyfamily.com/terryandann/" onclick="urchinTracker('/outgoing/www.aneyfamily.com/terryandann/?referer=');">Terry Aney</a> did an amazing job.</p>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/tips/batch-updates-and-deletes-with-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Repositories and Presentation</title>
		<link>http://wizardsofsmart.net/uncategorized/repositories-and-presentation/</link>
		<comments>http://wizardsofsmart.net/uncategorized/repositories-and-presentation/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 15:22:13 +0000</pubDate>
		<dc:creator>panesofglass</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Active Record]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Domain Model]]></category>
		<category><![CDATA[Presentation Layer]]></category>
		<category><![CDATA[Repository]]></category>
		<category><![CDATA[Unit of Work]]></category>

		<guid isPermaLink="false">http://wizardsofsmart.net/?p=96</guid>
		<description><![CDATA[I recently came upon a question in the Domain Driven Design Yahoo! Groups asking whether or not the presentation layer should interact directly with repositories or through a method on the entity (domain model). Having just finished Nilsson&#8217;s Applying Domain Driven Design Patterns and (finally) getting my head around LINQ to SQL on my current [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Sql Designer" href="http://flickr.com/photos/74609962@N00/808461304" onclick="urchinTracker('/outgoing/flickr.com/photos/74609962_N00/808461304?referer=');"><img src="http://farm2.static.flickr.com/1329/808461304_0728df4aa4_m.jpg" alt="" /></a>I recently came upon a <a title="domaindrivendesign Yahoo! Groups" href="http://tech.groups.yahoo.com/group/domaindrivendesign/message/9316" onclick="urchinTracker('/outgoing/tech.groups.yahoo.com/group/domaindrivendesign/message/9316?referer=');">question in the Domain Driven Design Yahoo! Groups</a> asking whether or not the presentation layer should interact directly with repositories or through a method on the entity (domain model). Having just finished <a title="Applying Domain Driven Design and Patterns on Amazon.com" href="http://www.amazon.com/Applying-Domain-Driven-Design-Patterns-Examples/dp/0321268202/?tag=panesofglass-20" onclick="urchinTracker('/outgoing/www.amazon.com/Applying-Domain-Driven-Design-Patterns-Examples/dp/0321268202/?tag=panesofglass-20&amp;referer=');">Nilsson&#8217;s Applying Domain Driven Design Patterns</a> and (finally) getting my head around LINQ to SQL on my current project, I decided to weigh in on the matter.</p>
<p>As always, it depends. You can indeed allow the presentation layer to use the repository directly, just as you can allow the presentation layer to use a factory to create your entities. Your current implementation is something I started off with when I started trying to do <acronym title="Domain Driven Design">DDD</acronym>, and follows more of the <a title="Active Record on PoEAA" href="http://martinfowler.com/eaaCatalog/activeRecord.html" onclick="urchinTracker('/outgoing/martinfowler.com/eaaCatalog/activeRecord.html?referer=');">Active Record pattern</a>, as mentioned by another responder, thought Active Record, by definition, matches the database table field for field.</p>
<p>You have several options:</p>
<ol>
<li>Use your current approach. You&#8217;ll probably need to merge your repository and entity by using static methods and properties, though, which can make it messy, and I wouldn&#8217;t recommend it. That&#8217;s why I stopped using this approach, anyway.</li>
<li>Add a validation mechanism to your repository to validate your entities or, if your entities validate themselves, report the entities&#8217; validation before you save.</li>
<li>If you really like the Save method on your entity and you use .NET or a dynamic language (not sure about other platforms), you can use extension methods to &#8220;add&#8221; a Save method that wraps a call to your repository. This is really option 2 with some syntactic sugar.</li>
<li>BEST PRACTICE (?): Use a Unit of Work, such as LINQ to SQL&#8217;s DataContext, Entity Framework&#8217;s ObjectContext, or NHibernate&#8217;s / SubSonic 3&#8242;s ISession to manage transactions and repsoitories, then call SubmitChanges() through the unit of work.</li>
</ol>
<p>The <a title="Unit of Work on PoEAA" href="http://martinfowler.com/eaaCatalog/unitOfWork.html" onclick="urchinTracker('/outgoing/martinfowler.com/eaaCatalog/unitOfWork.html?referer=');">Unit of Work pattern</a> can be a little hard to understand at first, but it is quite powerful and great for managing rollbacks (which are extremely difficult if you always wrap your unit of work/repositories in the entity methods).</p>
<p>For reference, try these links:<br />
<a href="http://iridescence.no/post/ASPNET-MVC-DataContext-and-The-Unit-of-Work-Pattern.aspx" onclick="urchinTracker('/outgoing/iridescence.no/post/ASPNET-MVC-DataContext-and-The-Unit-of-Work-Pattern.aspx?referer=');"> http://iridescence.no/post/ASPNET-MVC-DataContext-and-The-Unit-of-Work-Pattern.aspx</a><br />
<a href="http://www.west-wind.com/weblog/posts/246222.aspx" onclick="urchinTracker('/outgoing/www.west-wind.com/weblog/posts/246222.aspx?referer=');"> http://www.west-wind.com/weblog/posts/246222.aspx</a></p>
<p>For keeping LINQ to SQL and Entity Framework persistence ignorant (PI), see:<br />
<a title="LINQ to SQL with POCO entities" href="http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!397.entry" onclick="urchinTracker('/outgoing/iancooper.spaces.live.com/blog/cns_844BD2811F9ABE9C_397.entry?referer=');"> http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!397.entry</a><br />
<a title="Entity Framework POCO Adapter" href="http://code.msdn.microsoft.com/EFPocoAdapter" onclick="urchinTracker('/outgoing/code.msdn.microsoft.com/EFPocoAdapter?referer=');"> http://code.msdn.microsoft.com/EFPocoAdapter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/uncategorized/repositories-and-presentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF DataBinding: Nullable Value Types</title>
		<link>http://wizardsofsmart.net/tips/wpf-databinding-nullable-value-types/</link>
		<comments>http://wizardsofsmart.net/tips/wpf-databinding-nullable-value-types/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 13:00:31 +0000</pubDate>
		<dc:creator>panesofglass</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[MSDN Code Gallery]]></category>
		<category><![CDATA[Nullable Types]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://panesofglass.com/?p=5</guid>
		<description><![CDATA[We recently ran into what appeared to be an inconsistency in WPF&#8217;s data binding. When you attempt to data bind to a nullable value type with a value of null, WPF appears to drop the binding. Using an identity converter and several other methods only told us what we already knew, so I did a [...]]]></description>
			<content:encoded><![CDATA[<p>We recently ran into what appeared to be an inconsistency in WPF&#8217;s data binding. When you attempt to data bind to a nullable value type with a value of null, WPF appears to drop the binding. Using an identity converter and several other methods only told us what we already knew, so I did a little research this morning.</p>
<p><a href="http://code.msdn.microsoft.com/UserAccount/UserProfile.aspx?UserName=hortha" onclick="urchinTracker('/outgoing/code.msdn.microsoft.com/UserAccount/UserProfile.aspx?UserName=hortha&amp;referer=');">hortha</a> posted a <a href="http://code.msdn.microsoft.com/wpfdatabindingnull" onclick="urchinTracker('/outgoing/code.msdn.microsoft.com/wpfdatabindingnull?referer=');">solution</a> with examples to the <a href="http://code.msdn.microsoft.com/" onclick="urchinTracker('/outgoing/code.msdn.microsoft.com/?referer=');">MSDN Code Gallery</a> that we tried this morning. His solution works beautifully. Several commenters noted that VS2008 SP1 is supposed to fix this without converters, but no one seems to have tried it.</p>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/tips/wpf-databinding-nullable-value-types/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WPF DataBinding: Refreshing from Source</title>
		<link>http://wizardsofsmart.net/tips/wpf-databinding-refreshing-from-source/</link>
		<comments>http://wizardsofsmart.net/tips/wpf-databinding-refreshing-from-source/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 13:00:27 +0000</pubDate>
		<dc:creator>panesofglass</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[DataContext]]></category>
		<category><![CDATA[INotifyPropertyChanged]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[ObservableCollection]]></category>
		<category><![CDATA[PresentationModel]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://panesofglass.com/?p=8</guid>
		<description><![CDATA[WPF DataBinding is terrific and allows for very passive views and easy source object updates. However, triggering updates in the view based on changes in the source object can be a little tricky. If you want to make sure changes to your source object are reflected in your view, your source object will need to [...]]]></description>
			<content:encoded><![CDATA[<p><abbr title="Windows Presentation Foundation">WPF</abbr> <a href="http://blogs.msdn.com/wpfsdk/archive/2006/10/19/wpf-basic-data-binding-faq.aspx" onclick="urchinTracker('/outgoing/blogs.msdn.com/wpfsdk/archive/2006/10/19/wpf-basic-data-binding-faq.aspx?referer=');">DataBinding</a> is terrific and allows for very passive views and easy source object updates. However, triggering updates in the view based on changes in the source object can be a little tricky.</p>
<p>If you want to make sure changes to your source object are reflected in your view, your source object will need to implement <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx" onclick="urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx?referer=');">INotifyPropertyChanged</a> (<a href="http://blogs.msdn.com/wpfsdk/archive/2006/10/19/wpf-basic-data-binding-faq.aspx" onclick="urchinTracker('/outgoing/blogs.msdn.com/wpfsdk/archive/2006/10/19/wpf-basic-data-binding-faq.aspx?referer=');">see example</a>). Yet just implementing this property will not necessarily update your bindings. If your source object includes collections, and you bind to properties in those collections, you can update the source property but will not get updates from the source property, even if it is of a type that implements INotifyPropertyChanged.</p>
<p>The above scenario is common with <a href="http://msdn.microsoft.com/en-us/library/bb386976.aspx" onclick="urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/bb386976.aspx?referer=');">Linq to Sql</a> when the entities are generated for you. Even tables with one-to-one mappings will be generated with lists&#8211;as SQL doesn&#8217;t have a way of representing one-to-one relationships&#8211;so be sure to edit your dbml accordingly in order to take advantage of binding to your source object&#8217;s properties. (You might also consider removing some relationships to remove issues with DataContext collisions when trying to set properties of one Linq entity to another.)</p>
<p>If you can&#8217;t fix the problem this way or want to display the collection and changes to the collection, you can always add an <a href="http://msdn.microsoft.com/en-us/library/ms668604.aspx" onclick="urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/ms668604.aspx?referer=');">ObservableCollection</a> to your <a href="http://me.catapultsystems.com/personal/rriley1/Blog/Lists/Posts/Post.aspx?ID=7" onclick="urchinTracker('/outgoing/me.catapultsystems.com/personal/rriley1/Blog/Lists/Posts/Post.aspx?ID=7&amp;referer=');">PresentationModel</a> or wrap the source object with another object that does use the ObservableCollection to display your collection.</p>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/tips/wpf-databinding-refreshing-from-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find a First/Last Row of Data Without Sub-Queries</title>
		<link>http://wizardsofsmart.net/tips/find-a-firstlast-row-of-data-without-sub-queries/</link>
		<comments>http://wizardsofsmart.net/tips/find-a-firstlast-row-of-data-without-sub-queries/#comments</comments>
		<pubDate>Tue, 27 May 2008 13:00:33 +0000</pubDate>
		<dc:creator>panesofglass</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Subquery]]></category>
		<category><![CDATA[Tally table]]></category>

		<guid isPermaLink="false">http://panesofglass.com/?p=37</guid>
		<description><![CDATA[Simple but effective&#8211;just follow the guidelines in this post. Performance is great, much better by far than using sub-queries. I found a marginal performance dip using this method versus the nine-fold performance hit using a sub-query.]]></description>
			<content:encoded><![CDATA[<p>Simple but effective&#8211;just follow the guidelines in <a title="How to find the max row per group in SQL without subqueries" href="http://www.xaprb.com/blog/2007/03/14/how-to-find-the-max-row-per-group-in-sql-without-subqueries/" onclick="urchinTracker('/outgoing/www.xaprb.com/blog/2007/03/14/how-to-find-the-max-row-per-group-in-sql-without-subqueries/?referer=');">this post</a>. Performance is great, much better by far than using sub-queries. I found a marginal performance dip using this method versus the nine-fold performance hit using a sub-query.</p>
]]></content:encoded>
			<wfw:commentRss>http://wizardsofsmart.net/tips/find-a-firstlast-row-of-data-without-sub-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
