<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.lostechies.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Mo Khan&amp;#39;s Blog</title><subtitle type="html" /><id>http://www.lostechies.com/blogs/mokhan/atom.aspx</id><link rel="alternate" type="text/html" href="http://www.lostechies.com/blogs/mokhan/default.aspx" /><link rel="self" type="application/atom+xml" href="http://www.lostechies.com/blogs/mokhan/atom.aspx" /><generator uri="http://communityserver.org" version="4.1.30929.2835">Community Server</generator><updated>2008-11-03T19:58:53Z</updated><entry><title>I Heart ReSharper!</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2009/04/03/i-heart-resharper.aspx" /><id>/blogs/mokhan/archive/2009/04/03/i-heart-resharper.aspx</id><published>2009-04-03T22:56:52Z</published><updated>2009-04-03T22:56:52Z</updated><content type="html">&lt;p&gt;I’m still surprised by just how many people still aren’t using ReSharper. It’s an amazing productivity adding for Microsoft Visual Studio.&amp;#160; Once you’ve spent the time learning a few keyboard shortcuts you will not go back to naked studio.&lt;/p&gt;  &lt;p&gt;There are few things that are more frustrating then jumping on a machine that doesn’t have ReSharper installed, then trying to edit some .cs files.&lt;/p&gt;  &lt;p&gt;In an effort to prevent myself from ever having to jump on a pc that’s still missing the glory of ReSharper, I decided to throw together a quick screen cast showcasing some of the features i enjoy.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://mokhan.ca/screencasts/rocknrolla/rock_n_rolla/rock_n_rolla.html"&gt;ReSharper Warm Fuzzies Screen cast&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you haven’t already… please, please &lt;a href="http://www.jetbrains.com/resharper/"&gt;give it a try&lt;/a&gt; (do it for me). It’s a good &lt;a href="http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.5+Nightly+Builds"&gt;addiction&lt;/a&gt;!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=I+Heart+ReSharper!&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f04%2f03%2fi-heart-resharper.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f04%2f03%2fi-heart-resharper.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=20135" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Tools" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Tools/default.aspx" /></entry><entry><title>Deploying .NET Applications – Learning MSBuild and ClickOnce</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2009/03/13/deploying-net-applications-learning-msbuild-and-clickonce.aspx" /><id>/blogs/mokhan/archive/2009/03/13/deploying-net-applications-learning-msbuild-and-clickonce.aspx</id><published>2009-03-13T19:56:50Z</published><updated>2009-03-13T19:56:50Z</updated><content type="html">&lt;p&gt;I recently finished reading…&lt;/p&gt;  &lt;table&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://www.amazon.com/gp/product/1590596528?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1590596528"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/51v5h50rHaL._SL160_.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1590596528" width="1" border="0" /&gt; &lt;/td&gt;        &lt;td&gt;&lt;a href="http://www.amazon.com/gp/product/1590596528?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1590596528"&gt;Deploying .NET Applications: Learning MSBuild and ClickOnce (Expert&amp;#39;s Voice in .Net)&lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1590596528" width="1" border="0" /&gt; &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;I was interested in this book mainly to find an easier way to deploy ClickOnce applications via an automated build. Most of my build automation experience has been with Nant, so I figured learning MSBuild couldn’t hurt.&lt;/p&gt;  &lt;p&gt;This book targets the Visual Studio 2005 time frame, so some of the things that it describes is out dated, mainly in regards to ClickCnce.&lt;/p&gt;  &lt;p&gt;There was a little coverage on mage.exe but not as much as I had liked. If you’re looking for a book to get you into the world of Clickonce or MSBuild, this one’s pretty good!&lt;/p&gt;  &lt;p&gt;Here are some of the things that I learned straight from the book. &lt;/p&gt;  &lt;h3&gt;MSBuild&lt;/h3&gt;  &lt;p&gt;Microsoft.Build.Framework and Microsoft.Build.Utilities contains some stuff to help you with your builds. There’s an ITask interface and a Task base class that you can implement if you want to run some custom tasks from MSBuild.&lt;/p&gt;  &lt;p&gt;ClickOnce is driven by two XML-based manifest files called the deployment manifest and the application manifest… &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Deployment manifest (.application) contains information specific to the deployment of the system. &lt;/li&gt;    &lt;li&gt;Application manifest (.manifest) captures information specific to version of the system. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;ClickOnce Deployment&lt;/h3&gt;  &lt;p&gt;The ClickOnce technology also has a programmatic interface that you can use to customize deployment and updates. For example, if you have a plug-in where the core of the application is deployed initially and then users are allowed to choose optional features (plug-ins) and have them installed on demand, the ClickOnce API can help.&lt;/p&gt;  &lt;p&gt;ClickOnce applications have to be deployed to a Web server, to a file server, and/or to removable media (such as CD/DVD). Moreover, you can deploy these applications in one of two modes: offline or online.&lt;/p&gt;  &lt;p&gt;For applications that require finer-grained control over doing updates, application authors can use the ClickOnce APIs to customize installation and updates.&lt;/p&gt;  &lt;h3&gt;Code Access Security (CAS)&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;Permission: The authority to do something. &lt;/li&gt;    &lt;li&gt;Permission set: A grouping of arbitrary permissions. &lt;/li&gt;    &lt;li&gt;Origin based Evidence: Where your code comes from determines what permissions your code gets. &lt;/li&gt;    &lt;li&gt;Content base evidence: Your code content is signed and has a publisher certificate, and that determines what permissions you get. &lt;/li&gt;    &lt;li&gt;Code Group: Associates evidence with a permission set &lt;/li&gt;    &lt;li&gt;Security Policy: Policies define a hierarchy of code groups. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;On-Demand Download&lt;/h3&gt;  &lt;p&gt;ClickOnce offers a facility that called on-demand download. The idea is that you create groups of files and then use the ClickOnce APIs to download each group at runtime. The initial download is reduced to what is needs to be downloaded to run the application, and if a piece of functionality is not needed, it is not downloaded.&lt;/p&gt;  &lt;p&gt;You can get the path to the Data directory via:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div style="font-size:14pt;background:black;color:white;font-family:consolas;"&gt;       &lt;pre style="margin:0px;"&gt;&lt;span style="color:yellow;"&gt;AppDomain&lt;/span&gt;.CurrentDomain.GetData(&lt;span style="color:lime;"&gt;&amp;quot;DataDirectory&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div style="font-size:14pt;background:black;color:white;font-family:consolas;"&gt;
      &lt;pre style="margin:0px;"&gt;&lt;span style="color:yellow;"&gt;ApplicationDeployment&lt;/span&gt;.CurrentDeployment.DataDirectory;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div style="font-size:14pt;background:black;color:white;font-family:consolas;"&gt;
      &lt;pre style="margin:0px;"&gt;&lt;span style="color:yellow;"&gt;Application&lt;/span&gt;.LocalUserAppDataPath;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Deploying+.NET+Applications+%e2%80%93+Learning+MSBuild+and+ClickOnce&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f13%2fdeploying-net-applications-learning-msbuild-and-clickonce.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f13%2fdeploying-net-applications-learning-msbuild-and-clickonce.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=19883" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Books" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Books/default.aspx" /></entry><entry><title>BDD on Creatine</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2009/03/12/bdd-on-creatine.aspx" /><id>/blogs/mokhan/archive/2009/03/12/bdd-on-creatine.aspx</id><published>2009-03-12T16:47:27Z</published><updated>2009-03-12T16:47:27Z</updated><content type="html">&lt;p&gt;In an attempt to further understand BDD, I chose to revise the code from my &lt;a href="http://mokhan.ca/blog/2009/03/11/BDD+On+Steroids.aspx"&gt;previous post&lt;/a&gt; after receiving some amazing advice from two people I regard highly (&lt;a href="http://blog.scottbellware.com/"&gt;Scott&lt;/a&gt; &amp;amp; &lt;a href="http://blog.jpboodhoo.com"&gt;JP&lt;/a&gt;). I should state that this is my interpretation of that advice. This may or may not be the direction they were trying to guide me towards.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="font-family:consolas;background:black;color:white;font-size:10pt;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 12&lt;/span&gt;&amp;#160;&lt;span style="color:#ff8000;"&gt;public&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;class&lt;/span&gt; &lt;span style="color:yellow;"&gt;when_prompted_to_save_changes_to_the_project&lt;/span&gt; : &lt;span style="color:yellow;"&gt;concerns_for&lt;/span&gt;&amp;lt;&lt;span style="color:yellow;"&gt;SaveChangesView&lt;/span&gt;&amp;gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 13&lt;/span&gt; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 14&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;context&lt;/span&gt; c = () =&amp;gt; { presenter = an&amp;lt;&lt;span style="color:#2b91af;"&gt;ISaveChangesPresenter&lt;/span&gt;&amp;gt;(); };&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 15&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 16&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;after_the_sut_has_been_created&lt;/span&gt; after = () =&amp;gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 17&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 18&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; save_changes_window = sut;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 19&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; save_changes_window.attach_to(presenter);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 20&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; };&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 21&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 22&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#ff8000;"&gt;protected&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ISaveChangesPresenter&lt;/span&gt; presenter;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 23&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#ff8000;"&gt;protected&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;static&lt;/span&gt; &lt;span style="color:yellow;"&gt;SaveChangesView&lt;/span&gt; save_changes_window;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 24&lt;/span&gt; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 25&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 26&lt;/span&gt;&amp;#160;&lt;span style="color:#ff8000;"&gt;public&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;class&lt;/span&gt; &lt;span style="color:yellow;"&gt;when_the_save_button_is_pressed&lt;/span&gt; : &lt;span style="color:yellow;"&gt;when_prompted_to_save_changes_to_the_project&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 27&lt;/span&gt; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 28&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;it&lt;/span&gt; should_save_the_current_project = () =&amp;gt; presenter.was_told_to(x =&amp;gt; x.save());&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 29&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 30&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;because&lt;/span&gt; b = () =&amp;gt; save_changes_window.save_button.control_is(x =&amp;gt; x.OnClick(&lt;span style="color:#ff8000;"&gt;new&lt;/span&gt; &lt;span style="color:yellow;"&gt;EventArgs&lt;/span&gt;()));&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 31&lt;/span&gt; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 32&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 33&lt;/span&gt;&amp;#160;&lt;span style="color:#ff8000;"&gt;public&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;class&lt;/span&gt; &lt;span style="color:yellow;"&gt;when_the_cancel_button_is_pressed&lt;/span&gt; : &lt;span style="color:yellow;"&gt;when_prompted_to_save_changes_to_the_project&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 34&lt;/span&gt; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 35&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;it&lt;/span&gt; should_not_continue_processing_the_previous_action = () =&amp;gt; presenter.was_told_to(x =&amp;gt; x.cancel());&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 36&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 37&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;because&lt;/span&gt; b = () =&amp;gt; save_changes_window.cancel_button.control_is(x =&amp;gt; x.OnClick(&lt;span style="color:#ff8000;"&gt;new&lt;/span&gt; &lt;span style="color:yellow;"&gt;EventArgs&lt;/span&gt;()));&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 38&lt;/span&gt; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 39&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 40&lt;/span&gt;&amp;#160;&lt;span style="color:#ff8000;"&gt;public&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;class&lt;/span&gt; &lt;span style="color:yellow;"&gt;when_the_do_not_save_button_is_pressed&lt;/span&gt; : &lt;span style="color:yellow;"&gt;when_prompted_to_save_changes_to_the_project&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 41&lt;/span&gt; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 42&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;it&lt;/span&gt; should_not_save_the_project = () =&amp;gt; presenter.was_told_to(x =&amp;gt; x.dont_save());&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 43&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 44&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;because&lt;/span&gt; b = () =&amp;gt; save_changes_window.do_not_save_button.control_is(x =&amp;gt; x.OnClick(&lt;span style="color:#ff8000;"&gt;new&lt;/span&gt; &lt;span style="color:yellow;"&gt;EventArgs&lt;/span&gt;()));&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 45&lt;/span&gt; }&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I hope this is slightly more soluble, then my &lt;a href="http://mokhan.ca/blog/2009/03/11/BDD+On+Steroids.aspx"&gt;previous post&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=BDD+on+Creatine&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f12%2fbdd-on-creatine.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f12%2fbdd-on-creatine.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=19849" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Windows Forms" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Windows+Forms/default.aspx" /><category term="TDD" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/TDD/default.aspx" /></entry><entry><title>BDD on Steroids</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2009/03/11/bdd-on-steroids.aspx" /><id>/blogs/mokhan/archive/2009/03/11/bdd-on-steroids.aspx</id><published>2009-03-11T20:41:36Z</published><updated>2009-03-11T20:41:36Z</updated><content type="html">&lt;p&gt;In the last couple of weeks I had a chance to sprinkle some of JP’s syntactic sugar, all over my projects. It’s amazing how much more concise my units test have become. I’ve had a couple of issues where I was mocking out the behavior of some Win Forms controls, but for the most part it’s been an awesome experience!&lt;/p&gt;  &lt;p&gt;I just wanted to take a moment to say Thank you JP! I am enjoying using your &lt;a href="http://subversion.assembla.com/svn/jpboodhoo_bdd/trunk/"&gt;BDD (on steroids) extensions&lt;/a&gt;. If you haven’t already you need to check it out &lt;a href="http://blog.jpboodhoo.com/developwithpassionbdd.aspx"&gt;here…&lt;/a&gt; NOW!&lt;/p&gt;  &lt;p&gt;Maaad, maaaad props Mr. JP!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="font-size:10pt;background:black;color:white;font-family:consolas;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 10&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#ff8000;"&gt;public&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;class&lt;/span&gt; &lt;span style="color:yellow;"&gt;behaves_like_save_changes_view_bound_to_presenter&lt;/span&gt; : &lt;span style="color:yellow;"&gt;concerns_for&lt;/span&gt;&amp;lt;&lt;span style="color:yellow;"&gt;SaveChangesView&lt;/span&gt;&amp;gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 11&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 12&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;context&lt;/span&gt; c = () =&amp;gt; { presenter = an&amp;lt;&lt;span style="color:#2b91af;"&gt;ISaveChangesPresenter&lt;/span&gt;&amp;gt;(); };&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 13&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 14&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;because&lt;/span&gt; b = () =&amp;gt; sut.attach_to(presenter);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 15&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 16&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#ff8000;"&gt;static&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;protected&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ISaveChangesPresenter&lt;/span&gt; presenter;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 17&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 18&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 19&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#ff8000;"&gt;public&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;class&lt;/span&gt; &lt;span style="color:yellow;"&gt;when_the_save_button_is_clicked&lt;/span&gt; : &lt;span style="color:yellow;"&gt;behaves_like_save_changes_view_bound_to_presenter&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 20&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 21&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;it&lt;/span&gt; should_forward_the_call_to_the_presenter = () =&amp;gt; presenter.was_told_to(x =&amp;gt; x.save());&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 22&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 23&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;because&lt;/span&gt; b = () =&amp;gt; &lt;span style="color:yellow;"&gt;EventTrigger&lt;/span&gt;.trigger_event&amp;lt;&lt;span style="color:yellow;"&gt;Events&lt;/span&gt;.&lt;span style="color:#2b91af;"&gt;ControlEvents&lt;/span&gt;&amp;gt;(&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 24&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; x =&amp;gt; x.OnClick(&lt;span style="color:#ff8000;"&gt;new&lt;/span&gt; &lt;span style="color:yellow;"&gt;EventArgs&lt;/span&gt;()),&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 25&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sut.ux_save_button&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 26&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; );&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 27&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 28&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 29&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#ff8000;"&gt;public&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;class&lt;/span&gt; &lt;span style="color:yellow;"&gt;when_the_cancel_button_is_clicked&lt;/span&gt; : &lt;span style="color:yellow;"&gt;behaves_like_save_changes_view_bound_to_presenter&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 30&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 31&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;it&lt;/span&gt; should_forward_the_call_to_the_presenter = () =&amp;gt; presenter.was_told_to(x =&amp;gt; x.cancel());&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 32&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 33&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;because&lt;/span&gt; b = () =&amp;gt; &lt;span style="color:yellow;"&gt;EventTrigger&lt;/span&gt;.trigger_event&amp;lt;&lt;span style="color:yellow;"&gt;Events&lt;/span&gt;.&lt;span style="color:#2b91af;"&gt;ControlEvents&lt;/span&gt;&amp;gt;(&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 34&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; x =&amp;gt; x.OnClick(&lt;span style="color:#ff8000;"&gt;new&lt;/span&gt; &lt;span style="color:yellow;"&gt;EventArgs&lt;/span&gt;()),&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 35&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sut.ux_cancel_button&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 36&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; );&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 37&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 38&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 39&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#ff8000;"&gt;public&lt;/span&gt; &lt;span style="color:#ff8000;"&gt;class&lt;/span&gt; &lt;span style="color:yellow;"&gt;when_the_do_not_save_button_is_clicked&lt;/span&gt; : &lt;span style="color:yellow;"&gt;behaves_like_save_changes_view_bound_to_presenter&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 40&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 41&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;it&lt;/span&gt; should_forward_the_call_to_the_presenter = () =&amp;gt; presenter.was_told_to(x =&amp;gt; x.dont_save());&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 42&lt;/span&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 43&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;because&lt;/span&gt; b = () =&amp;gt; &lt;span style="color:yellow;"&gt;EventTrigger&lt;/span&gt;.trigger_event&amp;lt;&lt;span style="color:yellow;"&gt;Events&lt;/span&gt;.&lt;span style="color:#2b91af;"&gt;ControlEvents&lt;/span&gt;&amp;gt;(&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 44&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; x =&amp;gt; x.OnClick(&lt;span style="color:#ff8000;"&gt;new&lt;/span&gt; &lt;span style="color:yellow;"&gt;EventArgs&lt;/span&gt;()),&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 45&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sut.ux_do_not_save_button&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 46&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; );&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#2b91af;"&gt;&amp;#160;&amp;#160; 47&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt; &lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=BDD+on+Steroids&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f11%2fbdd-on-steroids.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f11%2fbdd-on-steroids.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=19821" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="TDD" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/TDD/default.aspx" /><category term="Tools" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Tools/default.aspx" /></entry><entry><title>Data-Driven Services with Silverlight 2</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2009/03/11/data-driven-services-with-silverlight-2.aspx" /><id>/blogs/mokhan/archive/2009/03/11/data-driven-services-with-silverlight-2.aspx</id><published>2009-03-11T14:54:52Z</published><updated>2009-03-11T14:54:52Z</updated><content type="html">&lt;p&gt;I recently finished reading...&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.amazon.com/gp/product/0596523092?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0596523092"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/51psVmmlBZL._SL160_.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0596523092" width="1" border="0" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.amazon.com/gp/product/0596523092?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0596523092"&gt;Data-Driven Services with Silverlight 2&lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0596523092" width="1" border="0" /&gt;&lt;/p&gt;  &lt;p&gt;I have been wanting to get in to the world of WCF for some time now, but wasn’t really sure how to get started. This book was good at explaining how to get into WCF quick and easy. The sample apps that the author goes through and provides are pretty cool which makes it more fun.&lt;/p&gt;  &lt;p&gt;The book explains how data binding in silverlight (which seems to be similar to how it works in WPF), how to pass objects across the wire using WCF. It explains what RESTful services means, and how to build them leveraging tools on the .NET stack. &lt;/p&gt;  &lt;p&gt;The sample apps include one that consumes Amazon’s RESTful services, as well as a Twitter client called SilverTwit. There’s lots of code to dig through, and try out for yourself.&lt;/p&gt;  &lt;p&gt;For anyone interesting in Silverlight or WCF, this is a good book to get you started.&lt;/p&gt;  &lt;p&gt;If you’re looking for the &lt;a href="http://examples.oreilly.com/9780596523091/"&gt;sample code&lt;/a&gt; that comes with the book, you can find it here… &lt;a href="http://examples.oreilly.com/9780596523091/"&gt;http://examples.oreilly.com/9780596523091/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Data-Driven+Services+with+Silverlight+2&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f11%2fdata-driven-services-with-silverlight-2.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f11%2fdata-driven-services-with-silverlight-2.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=19808" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Books" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Books/default.aspx" /></entry><entry><title>Introducing NLP</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2009/03/02/introducing-nlp.aspx" /><id>/blogs/mokhan/archive/2009/03/02/introducing-nlp.aspx</id><published>2009-03-02T20:19:41Z</published><updated>2009-03-02T20:19:41Z</updated><content type="html">&lt;p&gt;I recently finished reading...&lt;/p&gt;  &lt;table&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;&lt;a href="http://www.amazon.com/gp/product/1855383446?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1855383446"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/413DF0NHGYL._SL160_.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1855383446" width="1" border="0" /&gt; &lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;&lt;a href="http://www.amazon.com/gp/product/1855383446?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1855383446"&gt;Introducing NLP: Psychological Skills for Understanding and Influencing People&lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1855383446" width="1" border="0" /&gt; &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I first heard about Neuro-linguistic programming (&lt;a href="http://en.wikipedia.org/wiki/Neuro-linguistic_programming"&gt;NLP&lt;/a&gt;) while I was reading &lt;a href="http://www.amazon.com/gp/product/0060554738?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0060554738"&gt;The Game: Penetrating the Secret Society of Pickup Artists&lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=mokhthliofawa-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0060554738" width="1" border="0" /&gt;. I thought that it sounded like an interesting subject, because I spend a good deal of my time dealing with people and trying to learn new things. If you&amp;#39;re interested in trying to become a better communicator or you are interested in trying to find out what your preferred way of learning is, this book will probably help!&lt;/p&gt;  &lt;p&gt;Below are some of the things that I learned straight from the book.&lt;/p&gt;  &lt;p&gt;The Four Stages of Learning&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Unconscious Incompetence &lt;/li&gt;    &lt;li&gt;Conscious Incompetence &lt;/li&gt;    &lt;li&gt;Conscious Competence &lt;/li&gt;    &lt;li&gt;Unconscious Competence &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;If you always do what you&amp;#39;ve always done, you&amp;#39;ll always get what you&amp;#39;ve got. If what you are doing is not working, do something else.&lt;/p&gt;  &lt;p&gt;Communication is so much more than the words we say. These form only a small part of our expressiveness as human beings. Research shows that in a presentation before a group of people, 55 per cent of the impact is determined by your body language - posture, gestures and eye contact - 38 per cent by your tone of voice, and only 7 per cent by the content of your presentation.&lt;/p&gt;  &lt;p&gt;We move our eyes in different directions in a systematic way depending on how we are thinking. Neurological studies have shown that eye movement both laterally and vertically seem to be associated with activating different parts of the brain.&lt;/p&gt;  &lt;p&gt;Movements and gestures will also tell you how a person is thinking. Many people will point to the sense organ that they are using internally: they will point to their ears while listening to sounds inside their head, point to the yes if visualizing, or to the abdomen if they are feeling something strongly. These signs will not tell you what a person is thinking about, only how he or she is thinking it. This is body language at a much more refined and subtle level than it is normally interpreted.&lt;/p&gt;  &lt;p&gt;Beliefs can be a matter of choice. You can drop beliefs that limit you and build beliefs that will make your life more fun and more successful. Positive beliefs allow you to find out what could be true and how capable you are. They are permissions to explore and play in the world of possibility.&lt;/p&gt;  &lt;p&gt;Towards people are energized by goals and rewards. Away people are motivated to avoid problems and punishment. Arguing which is best in general is futile. &lt;/p&gt;  &lt;p&gt;It is easy to recognize this pattern from a person&amp;#39;s language. Does she talk about what she wants, achieves or gains? Or does she tell you about the situation she wants to avoid and the problems to steer clear of? Towards people are best employed in goal-getting. Away from people are excellent at finding errors and work well in a job like quality control. Art critics usually have a strong away orientation as many a performing artist can testify!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;A good teacher will be able to create an environment, so her students learn for themselves how to get the results.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Learning to learn is the most important skill in education, and needs to be taught from reception class onwards. The educational system concentrates mostly on what is taught, the curriculum and omits the learning process. This has two consequences. First, many students have difficulty picking up the information. Secondly, even if they do learn it, it has little meaning for them, because it has been taken out of context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Introducing+NLP&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f02%2fintroducing-nlp.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f03%2f02%2fintroducing-nlp.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=19503" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Books" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Books/default.aspx" /></entry><entry><title>Object Thinking</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2009/02/12/object-thinking.aspx" /><id>/blogs/mokhan/archive/2009/02/12/object-thinking.aspx</id><published>2009-02-12T15:34:06Z</published><updated>2009-02-12T15:34:06Z</updated><content type="html">&lt;p&gt;I recently finished reading...&lt;/p&gt;  &lt;table&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;p&gt;&lt;a href="http://www.amazon.ca/gp/product/0735619654?ie=UTF8&amp;amp;tag=mokhmypo-20&amp;amp;linkCode=as2&amp;amp;camp=15121&amp;amp;creative=330641&amp;amp;creativeASIN=0735619654"&gt;&lt;img src="https://images-na.ssl-images-amazon.com/images/I/516hULBjUmL._SL160_.jpg" border="0" alt="" /&gt; &lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.ca/e/ir?t=mokhmypo-20&amp;amp;l=as2&amp;amp;o=15&amp;amp;a=0735619654" width="1" border="0" /&gt; &lt;/p&gt;       &lt;/td&gt;        &lt;td&gt;         &lt;p&gt;&lt;strong&gt;Object Thinking&lt;/strong&gt; &lt;em&gt;by David West&lt;/em&gt; &lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As usual I fold down pages that contain paragraphs that interest me... below are a few excerpts from the book that I enjoyed!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;quot;Better people&amp;quot; has been recognized as the most promising silver bullet for addressing the software crisis, and yet almost all of our energy has been spent on creating better tools, methods, and processes instead of better people?&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Imagine what a team of &amp;quot;better people&amp;quot; can accomplish. Now stop imaging, and start investing in fostering cultures that cultivate &amp;quot;better people&amp;quot; all working towards the same goal.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;An unspoken but just as widely held belief that really good developers were not to be trusted - they could not be &amp;quot;managed&amp;quot;, they all seemed to be &amp;quot;flaky&amp;quot; to some degree, and they did not exhibit the loyalty to company and paycheck of &amp;quot;normal&amp;quot; employees. Really &amp;quot;good&amp;quot; developers tended to be &amp;quot;artists&amp;quot;, and are was (is) not a good word in the context of software development.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Those flaky artist types... *sigh* It&amp;#39;s important to allow individuals do what they are good at, that&amp;#39;s obviously something they like to do. It breeds innovation, and efficiency. When working in a team it&amp;#39;s important to be respectful of one another&amp;#39;s opinions and work together. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Every once in a while someone on the team will have a crazy idea that just might slash the complexity of the whole system. If they have courage, they&amp;#39;ll try it out. It will work (sometimes).&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It&amp;#39;s important to have courage on any team. &lt;a href="http://mokhan.ca/blog/2007/08/31/The+Principles+And+Values+Of+XP.aspx"&gt;XP teams value courage&lt;/a&gt;. Without the courage to grow and challenge one another, your team will remain stagnant. By challenging one another you&amp;#39;re showing one another respect by saying that &amp;quot;I want you to get better, and I expect you to want me to get better as well&amp;quot;!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Object thinking is a &amp;quot;crazy idea&amp;quot; capable of increasing simplicity in software design - crazy in the sense that it does not conform to traditional thinking about software development, crazy in the sense that it revolts against the computer thinking employed by most software developers, and crazy in many of the same ways that XP is crazy.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Trying to introduce object&amp;#39;s into a culture that&amp;#39;s firmly devoted to thinking in terms of data can seem like a crazy idea too. There is a time and place for everything, I&amp;#39;m sure objects aren&amp;#39;t great for every system. A little bit of object &amp;quot;thinking&amp;quot; can help though, I&amp;#39;m sure. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;As a formalist, the computer scientist expects order and logic. The &amp;quot;goodness&amp;quot; of a program is directly proportional to the degree to which it can be formally described and formally manipulated. Proof - as in mathematical or logical proof - of correctness for a piece of software is an ultimate objective. All that is bad in software arises from deviations from formal descriptions that use precisely defined tokens and syntactic rules. Art has no place in a program. In fact, many formalists would take the extreme position: there is no such thing as art; art is nothing more than a formalism that has yet to be discovered and explicated.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Art is something that I enjoy. One of the reasons that I was drawn to software was the creative aspects of it. I first thought of developing software as a form of art. It&amp;#39;s great how Test Driven Development allows you to prove the correctness of a piece of software, but also enables you to refactor and be creative.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;An analogy to chess playing might illuminate the relationships among method categories. A beginning chess player follows rules and defined procedures (they are formalists), while a journeyman (informalist) relies on patterns and heuristics. A grandmaster has internalized and transcended the informal to become an aformal player.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I&amp;#39;m currently reading a book on &lt;a href="http://en.wikipedia.org/wiki/Neuro-linguistic_programming"&gt;NLP&lt;/a&gt;, and it describes how experts do most of their work subconsciously, instead of consciously. It&amp;#39;s like when you learn to drive a car (assuming you learned on a manual transmission). First you have a set of steps that you must follow, and repeat. Then you begin to follow patterns. (I used to look at my current speed to decide whether to shift gears.) Then you stop thinking about it, and you just drive.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;A human uses mechanical weights and machines in a gym to increase his innate capabilities - to make his own muscles strong and more reliable. Using a more cerebral metaphor (and one therefore more appropriate for object thinking), Kent Beck suggest using method and even XP practices as if they were etudes (musical exercises designed to help the musician internalize certain skills and techniques.)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Time and Focus equates to discipline, according to me.&amp;#160; In order to excel at something you need to invest both time and focus to truly excel at it. There really is no secret to getting better.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;A common tendency for new object developers is to list as responsibilities things that an object must &amp;quot;know.&amp;quot; An airplane must &amp;quot;know its current location.&amp;quot; While this may be true, it can be misleading. It implies too much about how the object might be implemented because &amp;quot;knows&amp;quot; implies an instance variable. It&amp;#39;s also quite possible that an object will know things (a private key for decryption, perhaps) that it will not be willing to share with others and that therefore will not be included in the interface for that object. &lt;em&gt;Provide private key &lt;/em&gt;would not appear as a service, although the message &lt;em&gt;privateKey&lt;/em&gt; might be in the object&amp;#39;s protocol with the designation that it is a private message. &lt;em&gt;Decrypt message&lt;/em&gt;, on the other hand, might be a listed responsibility. Always state your responsibilities in terms of a service, with an awareness of a possible client for that service.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I know when I first started transitioning from procedural to object oriented programming, I thought mostly about where and how the data was going to stored, and how to get the data. &amp;quot;This auditor class needs to have a sorted list of audits&amp;quot;... Now it&amp;#39;s a little more like &amp;quot;An auditor can submit an audit of a company to ...&amp;quot;&lt;/p&gt;  &lt;p&gt;This was a great read for anyone wanting to get into objects, or learn more about the history of objects. It was great to read about were a lot of present day ideas originated from.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Object+Thinking&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f02%2f12%2fobject-thinking.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2009%2f02%2f12%2fobject-thinking.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=16833" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Books" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Books/default.aspx" /></entry><entry><title>Shortening The Feedback Loop</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2008/12/10/shortening-the-feedback-loop.aspx" /><id>/blogs/mokhan/archive/2008/12/10/shortening-the-feedback-loop.aspx</id><published>2008-12-10T13:18:30Z</published><updated>2008-12-10T13:18:30Z</updated><content type="html">&lt;p&gt;Thank you everyone who attended &lt;a href="http://calgaryagile.com/node/25"&gt;our presentation&lt;/a&gt; last night at the &lt;a href="http://calgaryagile.com/"&gt;Calgary Agile Methodologies User Group&lt;/a&gt;. We had a tonne of fun, and hope that you took away some valuable information.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/mokhan/Image045_5F00_2.jpg"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="196" alt="CAMUG eCompliance" src="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/mokhan/Image045_5F00_thumb.jpg" width="244" border="0" /&gt;&lt;/a&gt;&lt;a href="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/mokhan/Image044_5F00_2.jpg"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="196" alt="CAMUG eCompliance" src="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/mokhan/Image044_5F00_thumb.jpg" width="244" border="0" /&gt;&lt;/a&gt;&amp;#160;&amp;#160; &lt;a href="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/mokhan/Image046_5F00_6.jpg"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="244" alt="CAMUG eCompliance" src="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/mokhan/Image046_5F00_thumb_5F00_2.jpg" width="196" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Shortening+The+Feedback+Loop&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f12%2f10%2fshortening-the-feedback-loop.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f12%2f10%2fshortening-the-feedback-loop.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=8987" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Teamwork" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Teamwork/default.aspx" /></entry><entry><title>Look Ma! Real Proxies...</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2008/12/03/look-ma-real-proxies.aspx" /><id>/blogs/mokhan/archive/2008/12/03/look-ma-real-proxies.aspx</id><published>2008-12-03T21:57:03Z</published><updated>2008-12-03T21:57:03Z</updated><content type="html">&lt;p&gt;I took some time today to pull down the source code for &lt;a href="http://www.codeplex.com/SvnBridge"&gt;SvnBridge&lt;/a&gt; today, and man, I was blown away. I started at Program.cs and made it to line 25 Bootstrapper.Start(). From there I went on to look at the hand rolled container, then the ProxyFactory.&lt;/p&gt;  &lt;p&gt;In order for me to fully grasp the System.Runtime.Remoting API for creating proxies I had to re-write the code from SVN Bridge.... I just had too... it&amp;#39;s just how I learn. It&amp;#39;s like tracing over cartoons when you&amp;#39;re a kid. I still do it!&lt;/p&gt;  &lt;p&gt;In case you&amp;#39;re interested, the attached code is the sample I put together that is derived from the source code of SvnBridge. If you haven&amp;#39;t checked out the source for the project, you really should.&lt;/p&gt;  &lt;p&gt;Pretty cool stuff.... Hopefully, this helps out anyone else who&amp;#39;s just as curious&lt;/p&gt;  &lt;p&gt;&lt;a href="http://mokhan.ca/blog/content/binary/proxies.zip"&gt;My reduced sample source code...&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="font-size:13pt;background:white;color:black;font-family:courier new;"&gt;   &lt;pre style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;{&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;var&lt;/span&gt; marshal_mathers = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Person&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;marshall mathers&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;var&lt;/span&gt; some_celebrity = &lt;span style="color:#2b91af;"&gt;ProxyFactory&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#2b91af;"&gt;IPerson&lt;/span&gt;&amp;gt;(marshal_mathers, &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;MyNameIsSlimShadyInterceptor&lt;/span&gt;());&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;try&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;var&lt;/span&gt; name = some_celebrity.what_is_your_name();&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; name.should_be_equal_to(&lt;span style="color:#a31515;"&gt;&amp;quot;slim shady&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;catch&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;Exception&lt;/span&gt; e)&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.Out.WriteLine(e);&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.Out.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;will the real slim shady please stand up...&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.In.ReadLine();&lt;/pre&gt;

  &lt;pre style="margin:0px;"&gt;}&lt;/pre&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Look+Ma!+Real+Proxies...&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f12%2f03%2flook-ma-real-proxies.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f12%2f03%2flook-ma-real-proxies.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=8472" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Design Patterns" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Design+Patterns/default.aspx" /></entry><entry><title>Who do you wanna Jott? Twitter</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2008/11/09/who-do-you-wanna-jott-twitter.aspx" /><id>/blogs/mokhan/archive/2008/11/09/who-do-you-wanna-jott-twitter.aspx</id><published>2008-11-10T02:44:01Z</published><updated>2008-11-10T02:44:01Z</updated><content type="html">&lt;p&gt;So I recently started twittering... or tweeting. I&amp;#39;m not sure what the correct lingo is, so hook me up if you know. It all started a while back when &lt;a href="http://codebetter.com/blogs/james.kovacs/archive/2008/09/07/i-cry-uncle.aspx"&gt;James&lt;/a&gt; announced that he was the newest Twit. He mentioned a WPF client called &lt;a href="http://code.google.com/p/wittytwitter/"&gt;Witty&lt;/a&gt;, and I wanted to see what it was all about. So I setup a &lt;a href="http://twitter.com/"&gt;Twitter&lt;/a&gt; account to play with the app. After I had my fun, I never deleted my account. Or at least I never looked into how to delete my account.&lt;/p&gt; &lt;p&gt;About a week ago I received and email that a couple of people were following me on &lt;a href="http://twitter.com/"&gt;Twitter&lt;/a&gt;. Man that&amp;#39;s flattering to read:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Hi, &lt;a href="http://twitter.com/mo_khan"&gt;mo_khan&lt;/a&gt;. &lt;br /&gt;Kyle Baley (kbaley) is now following your updates on Twitter. &lt;br /&gt;Check out Kyle Baley&amp;#39;s profile here: &lt;br /&gt;&lt;a href="http://twitter.com/kbaley"&gt;http://twitter.com/kbaley&lt;/a&gt; &lt;br /&gt;You may follow Kyle Baley as well by clicking on the &amp;quot;follow&amp;quot; button. &lt;br /&gt;Best, &lt;br /&gt;Twitter&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Whaa... a celeb is interested in what I&amp;#39;m up to? &lt;strong&gt;*blush*&lt;/strong&gt; So I jumped in, and so far it&amp;#39;s been pretty fun. I found another service called &lt;a href="http://jott.com/"&gt;&amp;quot;Jott&amp;quot;&lt;/a&gt;. Jott&amp;#39;s pretty cool, because I can call in to a number and I get an automated message that says:&lt;/p&gt; &lt;p&gt;&amp;quot;Who do you want to jott?&amp;quot;&lt;/p&gt; &lt;p&gt;I say ... &amp;quot;Twitter&amp;quot;. Then I record my voice message. &lt;/p&gt; &lt;p&gt;Jott then takes that message transcribes it in to text, pushes it up to my twitter page, and drops a tinyurl to the actual audio. Sweet... that saves me a few pennies worth of text messages. But there&amp;#39;s more...&lt;/p&gt; &lt;p&gt;I&amp;#39;m one of the poor saps who pay to much for mobile service up here in Canada, eh! I subscribe to &lt;a href="http://rogers.com"&gt;Rogers Wireless&lt;/a&gt;, and the plan called &lt;a href="http://your.rogers.com/store/wireless/services/voice/my5.asp"&gt;&amp;quot;My5&amp;quot;&lt;/a&gt;. I get to make unlimited phones calls to the 5 numbers that are in My5? So I put Jott on My5, and now I can shoot off messages to everyone for....&lt;/p&gt; &lt;p&gt;Free Ninety Nine.... well almost! If you&amp;#39;re young, fabulous and ghetto broke (it aint funny) like myself then you ought to give &lt;a href="http://jott.com/"&gt;Jott&lt;/a&gt; a try!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Who+do+you+wanna+Jott%3f+Twitter&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f09%2fwho-do-you-wanna-jott-twitter.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f09%2fwho-do-you-wanna-jott-twitter.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=6133" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Tools" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Tools/default.aspx" /></entry><entry><title>Container Configuration</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2008/11/09/container-configuration.aspx" /><id>/blogs/mokhan/archive/2008/11/09/container-configuration.aspx</id><published>2008-11-10T02:20:11Z</published><updated>2008-11-10T02:20:11Z</updated><content type="html">&lt;p&gt;In &lt;a href="http://mokhan.ca/blog/2008/11/09/Lazy+Loaded+Interceptors.aspx"&gt;my last post&lt;/a&gt; I briefly mentioned how we were wiring some components in to our container.&amp;nbsp; The syntax looked like the following:&lt;/p&gt;&lt;pre class="csharpcode"&gt;            container.AddProxyOf(
                &lt;span class="kwrd"&gt;new&lt;/span&gt; ReportPresenterTaskConfiguration(), 
                &lt;span class="kwrd"&gt;new&lt;/span&gt; ReportPresenterTask(
                    Lazy.Load&amp;lt;IReportDocumentBuilder&amp;gt;(),
                    Lazy.Load&amp;lt;IApplicationSettings&amp;gt;())
                    );&lt;/pre&gt;
&lt;p&gt;We&amp;#39;re using &lt;a href="http://www.castleproject.org/container/index.html"&gt;Castle Windsor&lt;/a&gt; under the hood, but we have an abstraction over it that allows us to configure it as we like. Even switching the underlying implementation. Which we did, from our hand rolled container to Castle Windsor. The implementation of the above method looks as follows:&lt;/p&gt;&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddProxyOf&amp;lt;Interface, Target&amp;gt;(IProxyConfiguration&amp;lt;Interface&amp;gt; configuration, Target instance)
            &lt;span class="kwrd"&gt;where&lt;/span&gt; Target : Interface
        {
            var builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; ProxyBuilder&amp;lt;Interface&amp;gt;();
            configuration.Configure(builder);
            AddInstanceOf(builder.CreateProxyFor(instance));
        }&lt;/pre&gt;


&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Proxy_pattern"&gt;Wikipedia defines the Proxy design pattern as&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A proxy, in its most general form, is a class functioning as an interface to another thing.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;To understand the ProxyBuilder&amp;lt;Interface&amp;gt; implementation you can checkout &lt;a href="http://blog.jpboodhoo.com/ExplicitStronglyTypedSelectiveProxies.aspx"&gt;JP&amp;#39;s strongly typed selective proxies&lt;/a&gt;. The &amp;quot;AddProxyOf&amp;quot; method creates an instance of a proxybuilder. It then passes it to the configuration to allow it to configure the proxy builder before building the proxy. Then it registers the proxy as a singleton in to the container.&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IConfiguration&amp;lt;T&amp;gt;
    {
        &lt;span class="kwrd"&gt;void&lt;/span&gt; Configure(T item_to_configure);
    }&lt;/pre&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IProxyConfiguration&amp;lt;T&amp;gt; : IConfiguration&amp;lt;IProxyBuilder&amp;lt;T&amp;gt;&amp;gt;
    {
    }&lt;/pre&gt;
&lt;p&gt;In this case the proxy configuration looks like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ReportPresenterTaskConfiguration : IProxyConfiguration&amp;lt;IReportPresenterTask&amp;gt;
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Configure(IProxyBuilder&amp;lt;IReportPresenterTask&amp;gt; builder)
        {
            var constraint = builder.AddInterceptor&amp;lt;DisplayProgressBarInterceptor&amp;gt;();
            constraint.InterceptOn.RetrieveAuditReport();
        }
    }&lt;/pre&gt;
&lt;p&gt;This guy adds a progress bar interceptor, that displays a progress bar as the report is getting generated via the &amp;quot;RetrieveAuditReport&amp;quot; method on the IReportPresenterTask. &lt;/p&gt;






&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Container+Configuration&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f09%2fcontainer-configuration.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f09%2fcontainer-configuration.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=6130" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Design Patterns" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Design+Patterns/default.aspx" /></entry><entry><title>Lazy Loaded Interceptors</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2008/11/09/lazy-loaded-interceptors.aspx" /><id>/blogs/mokhan/archive/2008/11/09/lazy-loaded-interceptors.aspx</id><published>2008-11-09T20:56:01Z</published><updated>2008-11-09T20:56:01Z</updated><content type="html">&lt;p&gt;&lt;a href="http://www.amazon.com/gp/product/0321127420?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0321127420"&gt;&lt;img src="http://mokhan.ca/blog/content/binary/51X1K7R6FGL._SL160_.jpg" align="left" border="0" alt="" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;a href="http://www.amazon.com/gp/product/0321127420?ie=UTF8&amp;amp;tag=mokhthliofawa-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0321127420"&gt;Patterns of Enterprise Application Architecture&lt;/a&gt;&lt;/strong&gt; defines &lt;strong&gt;Lazy Load&lt;/strong&gt; as:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;An object that doesn&amp;#39;t contain all of the data you need but knows how to get it.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;A while back I was trying to figure out how to lazy load objects from a container, so that I didn&amp;#39;t need to depend on the objects dependencies needing to be wired up in the correct order. The syntax I was looking for was something like the following....&lt;/p&gt;&lt;pre class="code"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="code"&gt;container.AddProxyOf(
    &lt;span style="color:blue;"&gt;new &lt;/span&gt;ReportPresenterTaskConfiguration(),
    &lt;span style="color:blue;"&gt;new &lt;/span&gt;ReportPresenterTask(
        &lt;span style="color:#2b91af;"&gt;Lazy&lt;/span&gt;.Load&amp;lt;IReportDocumentBuilder&amp;gt;(),
        &lt;span style="color:#2b91af;"&gt;Lazy&lt;/span&gt;.Load&amp;lt;IApplicationSettings&amp;gt;())
    );&lt;/pre&gt;
&lt;p&gt;Lazy.Load&amp;lt;T&amp;gt; will return a proxy in place of an actual implementation. This is just a temporary place holder that will forward the calls to the actual implementation. It wont load an instance of the actual type until the first time a call is made to it.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;when_calling_a_method_with_no_arguments_on_a_lazy_loaded_proxy &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;lazy_loaded_object_context
&lt;/span&gt;{
    [&lt;span style="color:#2b91af;"&gt;Observation&lt;/span&gt;]
    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;should_forward_the_original_call_to_the_target()
    {
        target.should_have_been_asked_to(t =&amp;gt; t.OneMethod());
    }

    &lt;span style="color:blue;"&gt;protected override void &lt;/span&gt;establish_context()
    {
        target = dependency&amp;lt;&lt;span style="color:#2b91af;"&gt;ITargetObject&lt;/span&gt;&amp;gt;();

        test_container
            .setup_result_for(t =&amp;gt; t.find_an_implementation_of&amp;lt;&lt;span style="color:#2b91af;"&gt;ITargetObject&lt;/span&gt;&amp;gt;())
            .will_return(target)
            .Repeat.Once();
    }

    &lt;span style="color:blue;"&gt;protected override void &lt;/span&gt;because_of()
    {
        &lt;span style="color:blue;"&gt;var &lt;/span&gt;result = &lt;span style="color:#2b91af;"&gt;Lazy&lt;/span&gt;.Load&amp;lt;&lt;span style="color:#2b91af;"&gt;ITargetObject&lt;/span&gt;&amp;gt;();
        result.OneMethod();
    }

    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ITargetObject &lt;/span&gt;target;
}&lt;/pre&gt;
&lt;p&gt;So when the method &amp;quot;OneMethod&amp;quot; is called on the proxy. It should forward the call to the target, which can be loaded from the container. The implementation depends on &lt;a href="http://www.castleproject.org/dynamicproxy/index.html"&gt;Castle DynamicProxy&lt;/a&gt;, and looks like the following...&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public static class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Lazy
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public static &lt;/span&gt;T Load&amp;lt;T&amp;gt;() &lt;span style="color:blue;"&gt;where &lt;/span&gt;T : &lt;span style="color:blue;"&gt;class
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;create_proxy_for&amp;lt;T&amp;gt;(create_interceptor_for&amp;lt;T&amp;gt;());
    }

    &lt;span style="color:blue;"&gt;private static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;LazyLoadedInterceptor&lt;/span&gt;&amp;lt;T&amp;gt; create_interceptor_for&amp;lt;T&amp;gt;() &lt;span style="color:blue;"&gt;where &lt;/span&gt;T : &lt;span style="color:blue;"&gt;class
    &lt;/span&gt;{
        &lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T&amp;gt; get_the_implementation = &lt;span style="color:#2b91af;"&gt;resolve&lt;/span&gt;.dependency_for&amp;lt;T&amp;gt;;
        &lt;span style="color:blue;"&gt;return new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;LazyLoadedInterceptor&lt;/span&gt;&amp;lt;T&amp;gt;(get_the_implementation.memorize());
    }

    &lt;span style="color:blue;"&gt;private static &lt;/span&gt;T create_proxy_for&amp;lt;T&amp;gt;(&lt;span style="color:#2b91af;"&gt;IInterceptor &lt;/span&gt;interceptor)
    {
        &lt;span style="color:blue;"&gt;return new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ProxyGenerator&lt;/span&gt;().CreateInterfaceProxyWithoutTarget&amp;lt;T&amp;gt;(interceptor);
    }
}

&lt;span style="color:blue;"&gt;internal class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;LazyLoadedInterceptor&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af;"&gt;IInterceptor
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T&amp;gt; get_the_implementation;

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;LazyLoadedInterceptor(&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T&amp;gt; get_the_implementation)
    {
        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.get_the_implementation = get_the_implementation;
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Intercept(&lt;span style="color:#2b91af;"&gt;IInvocation &lt;/span&gt;invocation)
    {
        &lt;span style="color:blue;"&gt;var &lt;/span&gt;method = invocation.GetConcreteMethodInvocationTarget();
        invocation.ReturnValue = method.Invoke(get_the_implementation(), invocation.Arguments);
    }
}

&lt;span style="color:blue;"&gt;public static class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;func_extensions
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T&amp;gt; memorize&amp;lt;T&amp;gt;(&lt;span style="color:blue;"&gt;this &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T&amp;gt; item) &lt;span style="color:blue;"&gt;where &lt;/span&gt;T : &lt;span style="color:blue;"&gt;class
    &lt;/span&gt;{
        T the_implementation = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;() =&amp;gt; {
                   &lt;span style="color:blue;"&gt;if &lt;/span&gt;(&lt;span style="color:blue;"&gt;null &lt;/span&gt;== the_implementation) {
                       the_implementation = item();
                   }
                   &lt;span style="color:blue;"&gt;return &lt;/span&gt;the_implementation;
               };
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;quot;resolve&amp;quot; is a &lt;a href="http://blog.jpboodhoo.com/TheStaticGatewayPattern.aspx"&gt;static gateway&lt;/a&gt; to the underlying IDependencyRegistry. This idea was totally inspired by JP&amp;#39;s &lt;a href="http://blog.jpboodhoo.com/ExplicitStronglyTypedSelectiveProxies.aspx"&gt;strongly typed selective proxies&lt;/a&gt;. If you haven&amp;#39;t already, you should definitely check it out.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mokhan.ca/blog/content/binary/interceptors.rar"&gt;Download the source.&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Lazy+Loaded+Interceptors&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f09%2flazy-loaded-interceptors.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f09%2flazy-loaded-interceptors.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=6123" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Design Patterns" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Design+Patterns/default.aspx" /><category term="Books" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Books/default.aspx" /><category term="TDD" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/TDD/default.aspx" /><category term="Tools" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Tools/default.aspx" /></entry><entry><title>Opening Doors</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2008/11/04/opening-doors.aspx" /><id>/blogs/mokhan/archive/2008/11/04/opening-doors.aspx</id><published>2008-11-04T19:27:33Z</published><updated>2008-11-04T19:27:33Z</updated><content type="html">&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://bitfed.com/"&gt;joshka&lt;/a&gt; left a comment on my &lt;a href="http://mokhan.ca/blog/2008/11/04/Intercepting+Business+Transactions.aspx"&gt;previous post&lt;/a&gt; that reads...&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&amp;quot;... Can you talk about the Application Context and IKey stuff a little in a future post?&amp;quot;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The IKey&amp;lt;T&amp;gt; interface defines a contract for different keys that are put into a dictionary. It depends on the implementation of the key to know how to parse its value out of the dictionary.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public interface &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IKey&lt;/span&gt;&amp;lt;T&amp;gt;
{
    &lt;span style="color:blue;"&gt;bool &lt;/span&gt;is_found_in(&lt;span style="color:#2b91af;"&gt;IDictionary &lt;/span&gt;items);
    T parse_from(&lt;span style="color:#2b91af;"&gt;IDictionary &lt;/span&gt;items);
    &lt;span style="color:blue;"&gt;void &lt;/span&gt;remove_from(&lt;span style="color:#2b91af;"&gt;IDictionary &lt;/span&gt;items);
    &lt;span style="color:blue;"&gt;void &lt;/span&gt;add_value_to(&lt;span style="color:#2b91af;"&gt;IDictionary &lt;/span&gt;items, T value);
}&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;An implementation of the key that we used for shoving an ISession into the HttpContext.Items collection is the TypedKey&amp;lt;T&amp;gt;. It creates a unique key based on type T.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;internal class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TypedKey&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af;"&gt;IKey&lt;/span&gt;&amp;lt;T&amp;gt;
{
    &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;is_found_in(&lt;span style="color:#2b91af;"&gt;IDictionary &lt;/span&gt;items)
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;items.Contains(create_unique_key());
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;T parse_from(&lt;span style="color:#2b91af;"&gt;IDictionary &lt;/span&gt;items)
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;(T) items[create_unique_key()];
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;remove_from(&lt;span style="color:#2b91af;"&gt;IDictionary &lt;/span&gt;items)
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(is_found_in(items))
        {
            items.Remove(create_unique_key());
        }
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;add_value_to(&lt;span style="color:#2b91af;"&gt;IDictionary &lt;/span&gt;items, T value)
    {
        items[create_unique_key()] = value;
    }

    &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;Equals(&lt;span style="color:#2b91af;"&gt;TypedKey&lt;/span&gt;&amp;lt;T&amp;gt; obj)
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;!ReferenceEquals(&lt;span style="color:blue;"&gt;null&lt;/span&gt;, obj);
    }

    &lt;span style="color:blue;"&gt;public override bool &lt;/span&gt;Equals(&lt;span style="color:blue;"&gt;object &lt;/span&gt;obj)
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(ReferenceEquals(&lt;span style="color:blue;"&gt;null&lt;/span&gt;, obj)) &lt;span style="color:blue;"&gt;return false&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(ReferenceEquals(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, obj)) &lt;span style="color:blue;"&gt;return true&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(obj.GetType() != &lt;span style="color:blue;"&gt;typeof &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;TypedKey&lt;/span&gt;&amp;lt;T&amp;gt;)) &lt;span style="color:blue;"&gt;return false&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;Equals((&lt;span style="color:#2b91af;"&gt;TypedKey&lt;/span&gt;&amp;lt;T&amp;gt;) obj);
    }

    &lt;span style="color:blue;"&gt;public override int &lt;/span&gt;GetHashCode()
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;GetType().GetHashCode();
    }

    &lt;span style="color:blue;"&gt;private string &lt;/span&gt;create_unique_key()
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;GetType().FullName;
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;It knows how to add a value in to the dictionary using it as the key, and how to parse values from the dictionary using it. The application context can be an adapter around the HttpContext, or a hand rolled context for win forms. An implementation on the web might look like....&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebContext &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IApplicationContext
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;contains&amp;lt;T&amp;gt;(&lt;span style="color:#2b91af;"&gt;IKey&lt;/span&gt;&amp;lt;T&amp;gt; key)
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;key.is_found_in(&lt;span style="color:#2b91af;"&gt;HttpContext&lt;/span&gt;.Current.Items);
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;add&amp;lt;T&amp;gt;(&lt;span style="color:#2b91af;"&gt;IKey&lt;/span&gt;&amp;lt;T&amp;gt; key, T value)
    {
        key.add_value_to(&lt;span style="color:#2b91af;"&gt;HttpContext&lt;/span&gt;.Current.Items, value);
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;T get_value_for&amp;lt;T&amp;gt;(&lt;span style="color:#2b91af;"&gt;IKey&lt;/span&gt;&amp;lt;T&amp;gt; key)
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;key.parse_from(&lt;span style="color:#2b91af;"&gt;HttpContext&lt;/span&gt;.Current.Items);
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;remove(&lt;span style="color:#2b91af;"&gt;IKey&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;ISession&lt;/span&gt;&amp;gt; key)
    {
        key.remove_from(&lt;span style="color:#2b91af;"&gt;HttpContext&lt;/span&gt;.Current.Items);
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;When running your integration tests, you can swap out the implementation with an implementation specific to running unit tests. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Opening+Doors&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f04%2fopening-doors.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f04%2fopening-doors.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5979" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="Design Patterns" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/Design+Patterns/default.aspx" /></entry><entry><title>Mocking Queryables</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2008/11/04/mocking-queryables.aspx" /><id>/blogs/mokhan/archive/2008/11/04/mocking-queryables.aspx</id><published>2008-11-04T15:59:09Z</published><updated>2008-11-04T15:59:09Z</updated><content type="html">&lt;p&gt;Recently, we&amp;#39;ve been mocking out IQueryable&amp;#39;s as return values, which had led to setups that look like the following...&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;pre&gt;programs.setup_result_for(x =&amp;gt; x.All()).Return(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;IProgram&lt;/span&gt;&amp;gt; {active_program,inactive_program}.AsQueryable());&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I just switched over to the following syntax... by creating an extension method.&lt;/p&gt;

&lt;pre class="code"&gt;programs.setup_result_for(x =&amp;gt; x.All()).will_return(active_program,inactive_program);&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following are the extensions methods to make this work.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IMethodOptions&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;R&amp;gt;&amp;gt; will_return&amp;lt;R&amp;gt;(&lt;span style="color:blue;"&gt;this &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IMethodOptions&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;R&amp;gt;&amp;gt; options,
                                                            &lt;span style="color:blue;"&gt;params &lt;/span&gt;R[] items)
{
    &lt;span style="color:blue;"&gt;return &lt;/span&gt;options.Return(items);
}

&lt;span style="color:blue;"&gt;public static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IMethodOptions&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;IQueryable&lt;/span&gt;&amp;lt;R&amp;gt;&amp;gt; will_return&amp;lt;R&amp;gt;(&lt;span style="color:blue;"&gt;this &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IMethodOptions&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;IQueryable&lt;/span&gt;&amp;lt;R&amp;gt;&amp;gt; options,
                                                           &lt;span style="color:blue;"&gt;params &lt;/span&gt;R[] items)
{
    &lt;span style="color:blue;"&gt;return &lt;/span&gt;options.Return(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Query&lt;/span&gt;&amp;lt;R&amp;gt;(items));
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;and...&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;internal class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Query&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af;"&gt;IQueryable&lt;/span&gt;&amp;lt;T&amp;gt;
{
    &lt;span style="color:blue;"&gt;private readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IQueryable&lt;/span&gt;&amp;lt;T&amp;gt; query;

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;Query(&lt;span style="color:blue;"&gt;params &lt;/span&gt;T[] items)
    {
        query = items.AsQueryable();
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Expression &lt;/span&gt;Expression
    {
        &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;return &lt;/span&gt;query.Expression; }
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;ElementType
    {
        &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;return &lt;/span&gt;query.ElementType; }
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IQueryProvider &lt;/span&gt;Provider
    {
        &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;return &lt;/span&gt;query.Provider; }
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IEnumerator&lt;/span&gt;&amp;lt;T&amp;gt; GetEnumerator()
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;query.GetEnumerator();
    }

    &lt;span style="color:#2b91af;"&gt;IEnumerator IEnumerable&lt;/span&gt;.GetEnumerator()
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;GetEnumerator();
    }
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Hope, this helps!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Mocking+Queryables&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f04%2fmocking-queryables.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f04%2fmocking-queryables.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5976" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author><category term="TDD" scheme="http://www.lostechies.com/blogs/mokhan/archive/tags/TDD/default.aspx" /></entry><entry><title>Intercepting Business Transactions</title><link rel="alternate" type="text/html" href="/blogs/mokhan/archive/2008/11/03/intercepting-business-transactions.aspx" /><id>/blogs/mokhan/archive/2008/11/03/intercepting-business-transactions.aspx</id><published>2008-11-04T01:58:53Z</published><updated>2008-11-04T01:58:53Z</updated><content type="html">&lt;p&gt;In &lt;a href="http://www.amazon.com/Enterprise-Application-Architecture-Addison-Wesley-Signature/dp/0321127420"&gt;Patterns of Enterprise Application Architecture&lt;/a&gt;, the Unit of Work design pattern is defined as:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;i&gt;Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.&lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;NHibernate seems to have a great implementation of the unit of work, but understanding when to start and commit the unit of work without repeating yourself can be a little tricky. One thing we&amp;#39;ve been doing is starting a unit of work using an interceptor.&lt;/p&gt;&lt;pre class="code"&gt;[&lt;span style="color:#2b91af;"&gt;Interceptor&lt;/span&gt;(&lt;span style="color:blue;"&gt;typeof &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;IUnitOfWorkInterceptor&lt;/span&gt;))]
&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;AccountTasks &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IAccountTasks
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;are_valid(&lt;span style="color:#2b91af;"&gt;ICredentials &lt;/span&gt;credentials)
    {
        &lt;font color="#0000ff"&gt;...&lt;/font&gt;
    }
}&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Account tasks is a service layer piece, that is decorated with an interceptor that will begin and commit a unit of work. &lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public interface &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IUnitOfWorkInterceptor &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IInterceptor
&lt;/span&gt;{}

&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;UnitOfWorkInterceptor &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IUnitOfWorkInterceptor
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IUnitOfWorkFactory &lt;/span&gt;factory;

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;UnitOfWorkInterceptor(&lt;span style="color:#2b91af;"&gt;IUnitOfWorkFactory &lt;/span&gt;factory)
    {
        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.factory = factory;
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Intercept(&lt;span style="color:#2b91af;"&gt;IInvocation &lt;/span&gt;invocation)
    {
        &lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:blue;"&gt;var &lt;/span&gt;unit_of_work = factory.create()) {
            invocation.Proceed();
            unit_of_work.commit();
        }
    }
}&lt;/pre&gt;
&lt;p&gt;The interceptor starts a new unit of work, before proceeding with the invocation. If no exceptions are raised the unit of work is committed. If a unit of work is already started, the unit of work factory returns an empty unit of work. This ensures that if a service layer method calls into another method that it doesn&amp;#39;t start another unit of work.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public interface &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IUnitOfWorkFactory &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IFactory&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;IUnitOfWork&lt;/span&gt;&amp;gt;
{}

&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;UnitOfWorkFactory &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IUnitOfWorkFactory
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IApplicationContext &lt;/span&gt;context;
    &lt;span style="color:blue;"&gt;private readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IDatabaseSessionFactory &lt;/span&gt;factory;
    &lt;span style="color:blue;"&gt;private readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TypedKey&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;ISession&lt;/span&gt;&amp;gt; key;

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;UnitOfWorkFactory(&lt;span style="color:#2b91af;"&gt;IApplicationContext &lt;/span&gt;context, &lt;span style="color:#2b91af;"&gt;IDatabaseSessionFactory &lt;/span&gt;factory)
    {
        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.context = context;
        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.factory = factory;
        key = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TypedKey&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;ISession&lt;/span&gt;&amp;gt;();
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IUnitOfWork &lt;/span&gt;Create()
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(unit_of_work_is_already_started()) {
            &lt;span style="color:blue;"&gt;return new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EmptyUnitOfWork&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;return &lt;/span&gt;create_a_unit_of_work().start();
    }

    &lt;span style="color:blue;"&gt;private bool &lt;/span&gt;unit_of_work_is_already_started()
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;context.contains(key);
    }

    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IUnitOfWork &lt;/span&gt;create_a_unit_of_work()
    {
        &lt;span style="color:blue;"&gt;var &lt;/span&gt;session = factory.create();
        context.add(key, session);
        &lt;span style="color:blue;"&gt;return new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;UnitOfWork&lt;/span&gt;(session, context);
    }
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;The implementation of the repository pulls the active session from the application context. &lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DatabaseRepository&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af;"&gt;IRepository&lt;/span&gt;&amp;lt;T&amp;gt;
{
    &lt;span style="color:blue;"&gt;private readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IApplicationContext &lt;/span&gt;context;
    &lt;span style="color:blue;"&gt;private readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IKey&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;ISession&lt;/span&gt;&amp;gt; session_key;

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;DatabaseRepository(&lt;span style="color:#2b91af;"&gt;IApplicationContext &lt;/span&gt;context)
    {
        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.context = context;
        session_key = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TypedKey&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;ISession&lt;/span&gt;&amp;gt;();
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IQueryable&lt;/span&gt;&amp;lt;T&amp;gt; all()
    {
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;the_current_session().Linq&amp;lt;T&amp;gt;();
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;save(T item)
    {
        the_current_session().SaveOrUpdate(item);
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;delete(T item)
    {
        the_current_session().Delete(item);
    }

    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ISession &lt;/span&gt;the_current_session()
    {
        &lt;span style="color:blue;"&gt;var &lt;/span&gt;current_session = context.get_value_for(session_key);
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(&lt;span style="color:blue;"&gt;null &lt;/span&gt;== current_session || !current_session.IsOpen) {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NHibernateSessionNotOpenException&lt;/span&gt;();
        }
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;current_session;
    }
}&lt;/pre&gt;For more information on Interceptors check out the &lt;a href="http://www.castleproject.org/container/documentation/trunk/usersguide/interceptors.html"&gt;Castle stack...&lt;/a&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Intercepting+Business+Transactions&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f03%2fintercepting-business-transactions.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fmokhan%2farchive%2f2008%2f11%2f03%2fintercepting-business-transactions.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=5969" width="1" height="1"&gt;</content><author><name>mo.khan</name><uri>http://www.lostechies.com/members/mo.khan/default.aspx</uri></author></entry></feed>