<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>CodeBetter.Com - Stuff you need to Code Better!</title><link>http://codebetter.com/blogs/</link><description>Stuff you need to code better!</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CodeBetter" /><feedburner:info uri="codebetter" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><item><title>More signs of FubuMVC getting real</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/RKEgz8nDo9I/more-signs-of-fubumvc-getting-real.aspx</link><pubDate>Tue, 09 Feb 2010 14:52:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:624127</guid><dc:creator>Jeremy D. Miller</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Just launched last night:&amp;nbsp; &lt;a href="http://guides.fubumvc.com/"&gt;http://guides.fubumvc.com/.&lt;/a&gt;&amp;nbsp; The main page has been around for a couple weeks now at &lt;a href="http://fubumvc.com/"&gt;http://fubumvc.com/.&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s not that much yet, but I think the existence of *any* documentation at this point is a good indication that we&amp;#39;re serious about making the FubuMVC reboot take off.&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re interested in getting involved, there&amp;#39;s a TODO list that Chad &amp;amp; I are trying to keep up with ideas for extending FubuMVC at &lt;a href="http://wiki.fubumvc.com/TODO"&gt;http://wiki.fubumvc.com/TODO&lt;/a&gt; and the developers list is at &lt;a href="http://groups.google.com/group/fubumvc-devel"&gt;http://groups.google.com/group/fubumvc-devel&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=624127" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/RKEgz8nDo9I" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/jeremy.miller/archive/tags/FubuMVC/default.aspx">FubuMVC</category><feedburner:origLink>http://codebetter.com/blogs/jeremy.miller/archive/2010/02/09/more-signs-of-fubumvc-getting-real.aspx</feedburner:origLink></item><item><title>VS 2010 RC1 available on MSDN</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/mZkki9DtbNE/vs-2010-rc1-available-on-msdn.aspx</link><pubDate>Tue, 09 Feb 2010 11:05:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:624107</guid><dc:creator>Patrick Smacchia</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;... and this RC1 will go public in 3 days. (if your are logged in MSDN, the link is: &lt;a target="_blank" href="https://msdn.microsoft.com/en-us/subscriptions/securedownloads/default.aspx?pv=18%3a370"&gt;https://msdn.microsoft.com/en-us/subscriptions/securedownloads/default.aspx?pv=18%3a370&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;I had access to the Release Candidate 1 limited community editions for a month, and I can say that hopefully, overall stability, performance and memory consumption have been greatly enhanced. As many, I was pretty angry with VS2010 beta2 performance and stability and it is good to see that MS engineers were able to address all these.&lt;/p&gt;
&lt;p&gt;Also, a huge thanks to the &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/vsx2008/products/dd637761.aspx"&gt;Visual Studio Partners team&lt;/a&gt; that was pretty responsive and efficient during the last weeks. Thanks to their help, &lt;a target="_blank" href="http://www.ndepend.com/Version3BetaProgram.aspx"&gt;NDepend v3 beta3,&lt;/a&gt; &lt;a target="_blank" href="http://codebetter.com/blogs/patricksmacchia/archive/2010/01/28/ndepend-v3-is-now-100-integrated-in-visual-studio.aspx"&gt;I announced 12 days ago&lt;/a&gt;, works 100% with this VS 2010 RC1 version.We hope to have a NDepend v3 Release Candidate during next week. &lt;/p&gt;
&lt;p&gt;Also, we prepared a &lt;a target="_blank" href="http://www.ndepend.com/OverviewTour/NDependOverviewTour.html"&gt;screencast overview tour&lt;/a&gt; for this upcoming release integrated in Visual Studio 2010, 2008 and 2005. The fun part was that we used a &lt;a target="_blank" href="http://www.acapela-group.com/text-to-speech-interactive-demo.html"&gt;synthesized English speaker&lt;/a&gt; for the speech in the screencast (it is Ryan US in the combo box). The reason is that in our team, we all have &lt;i&gt;more or less&lt;/i&gt; strong French accent (I would say &lt;i&gt;more &lt;/i&gt;for me, you can get a glimpse in&lt;a target="_blank" href="http://www.hanselman.com/blog/CommentView.aspx?guid=dda4c3f4-119b-4f05-98a4-e4517c5668f3"&gt; this podcast with Scott Hanselman&lt;/a&gt;). (&lt;span style="text-decoration:underline;"&gt;Tip&lt;/span&gt;:&lt;i&gt; if you want to make your girlfriend or wife &lt;/i&gt;&lt;i&gt;laugh&lt;/i&gt;&lt;i&gt;, just type something sweet and make it say with the synthesized speaker&lt;/i&gt; &lt;img src="http://codebetter.com/emoticons/emotion-1.gif" alt="Smile" /&gt; ).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=624107" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/mZkki9DtbNE" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/patricksmacchia/archive/2010/02/09/vs-2010-rc1-available-on-msdn.aspx</feedburner:origLink></item><item><title>Exploring MongoDB with F#</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/ZkxqzVTAU5o/exploring-mongodb-with-f.aspx</link><pubDate>Tue, 09 Feb 2010 06:15:21 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:624081</guid><dc:creator>Matthew.Podwysocki</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;If you’ve been following me on &lt;a href="http://twitter.com/mattpodwysocki"&gt;Twitter&lt;/a&gt;, I’ve been digging a bit into &lt;a href="http://mongodb.org"&gt;MongoDB&lt;/a&gt;.&amp;#160; When I was involved with the planning of &lt;a href="http://nosqleast.com/2009/"&gt;NoSQLEast&lt;/a&gt; this past year, I sat down and used it in anger and was quite pleased with the results.&amp;#160; Using it with a language which allows for quick prototyping such as F# has afforded me to get up and going on a project with very little effort.&amp;#160; At some point, I don’t want to be bothered with having to go into another tool, create a schema, decide what data types, run migrations and all the fun things that come along with traditional RDBMS solutions. I just want a quick answer with the data I have.&amp;#160; There was one issue of course that nagged me which was the ubiquitous use of strings for everything from databases, collections, and keys.&amp;#160; With a language such as F#, could we do any better than this approach?&lt;/p&gt;  &lt;h2&gt;From Dictionaries&lt;/h2&gt;  &lt;p&gt;Before we look at any potential solution, let’s first look at how we insert a document using the normal string approach with the &lt;a href="http://github.com/samus/mongodb-csharp"&gt;C# MongoDB Driver&lt;/a&gt;.&amp;#160; Let’s take books for a potential book reviewing system as an example.&amp;#160; Let’s first insert a document into the collection.&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c97fee2d-7ae4-4a2f-a00c-3c2d8cd32b6f" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;open&lt;/span&gt;&lt;span style="color:#000000;"&gt; MongoDB.Driver

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; Mongo()
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; not &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo.Connect() &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;then&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  failwith &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Could not connect to MongoDB instance&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; books &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;BookReviews&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;].[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Books&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]

&lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Insert a book&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; book1 &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; Document()
book1.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Title&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Programming F#&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
book1.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Authors&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; [&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Chris Smith&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]
book1.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Publisher&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;O&amp;#39;Reilly&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
book1[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rating&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;5.0&lt;/span&gt;&lt;span style="color:#000000;"&gt;

books.Insert(book1)
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In the code above, I connected to the MongoDB instance I have running locally.&amp;#160; After that, I browse to the BookReviews database and then to the Books collection.&amp;#160; What’s interesting about that last piece is that if it doesn’t exist already, MongoDB will create it for me, so that saved me quite a bit from having to go into another tool, create a database, define columns, set indexes, etc.&amp;#160; After I get the Books collection, I then create a new Document with some keys and insert it into the collection.&amp;#160; Now, how about querying?&amp;#160; Let’s say I want to get all books by O’Reilly publishing.&amp;#160; How would I do it?&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:28537ca1-6bbd-4a1b-b6f1-f9437fd1f802" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; oreillyQuery &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; Document()
query.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Publisher&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;O&amp;#39;Reilly&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; oReillyBooks &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; books.Find(oReillyQuery)
printfn &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;O&amp;#39;Reilly books %d&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; Seq.length oReillyBooks.Documents

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; not &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo.Disconnect() &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;then&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  failwith &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Could not disconnect from MongoDB instance&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As you can see from the code above, we simply need to create a query document and set the appropriate keys.&amp;#160; Then we use the books collection to find it based upon our query.&amp;#160; Overall, it’s a great experience, but that’s an awful lot of string usage, more than my taste usually allows.&amp;#160; What can we do about it?&lt;/p&gt;

&lt;h2&gt;To Dynamic&lt;/h2&gt;

&lt;p&gt;As we covered in the &lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2010/02/05/using-and-abusing-the-f-dynamic-lookup-operator.aspx"&gt;previous post&lt;/a&gt;, F# has added support for both a dynamic get ( ? ) and set operator ( ?&amp;lt;-).&amp;#160; Note, that I said support and not actual implementation.&amp;#160; The actual implementation is up to you and your need.&amp;#160; There are a couple of solutions that we could explore on making our lives easier with this operator.&amp;#160; Ultimately, our goal is to look something like the following:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:3e5afafa-77fd-4e59-b0f8-f12738da9c9f" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; Mongo()
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; not &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo.Connect() &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;then&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  failwith &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Could not connect to MongoDB instance&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; books &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;BookReviews&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;].[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Books&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; book &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; Document()
book&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Title &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Real World Haskell&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
book&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Authors &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; [&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Bryan O&amp;#39;Sullivan&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;John Gorezen&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Don Stewart&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]
book&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Publisher &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;O&amp;#39;Reilly&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
book&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Rating &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;4.6&lt;/span&gt;&lt;span style="color:#000000;"&gt;

books.Insert(book)

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; not &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo.Disconnect() &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;then&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  failwith &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Could not disconnect from MongoDB instance&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Or better yet, rid ourselves of the strings altogether such as BookReviews and Books.&amp;#160; One solution could be to use the incoming type in the ? operator to be an IDictionary as the MongoDB C# Driver Document class is based off an IDictionary.&amp;#160; &lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f25d4ff1-65d9-4e9c-b071-372f64be947b" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;open&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.Collections

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (this : IDictionary) key &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  this.[key]

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (this : IDictionary) key value &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  this.[key] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; value&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This will allow for our calls to the document to be just as I wanted in the beginning.&amp;#160; But, that doesn’t cover how I could possibly cover the case for getting our database and our collection.&amp;#160; One common thread between the two of them is the indexed property of Item.&amp;#160; With that in hand, we could revisit the idea of using member restrictions to model this dynamic lookup of both gets and sets.&amp;#160; Let’s look at the code required for setting these member restrictions.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:4bbb8920-6b31-4855-8d86-33e42337115e" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;inline&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;) this key &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  ( &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;a : (&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; get_Item : &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;b &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;c) (this,key))
 
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;inline&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt;) this key value &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  ( &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;a : (&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; set_Item : &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;b &lt;/span&gt;&lt;span style="color:#000000;"&gt;*&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;c &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;d) (this,key,value))&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;This gives us not only the ability to deal with our Documents much as we had above, but also change our calls to get our database and collection, such as:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:52f38946-09db-44ad-91e7-1e37e9db02ea" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Old&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; books &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;BookReviews&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;].[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Books&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]

&lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; New&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; books &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; mongo&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;BookReviews&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Books&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;But, ultimately, as I pointed out in the last post, this has potential problems due to the nature of how F# treats the get_Item and set_Item properties.&amp;#160; For example, this solution does not work quite well with LINQ, such as the following will return an error.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d40c5d52-9486-4f91-8a63-a17b139fe6a0" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; d &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; [dict [(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;dynamic&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#800080;"&gt;123&lt;/span&gt;&lt;span style="color:#000000;"&gt;)];  dict [(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;dynamic&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#800080;"&gt;456&lt;/span&gt;&lt;span style="color:#000000;"&gt;)]]

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; allDynamics &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  query &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;@ seq { &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; m &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; d.AsQueryable() &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;
                   &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;yield&lt;/span&gt;&lt;span style="color:#000000;"&gt; m&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;dynamic } @&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
                   
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;val&lt;/span&gt;&lt;span style="color:#000000;"&gt; alllDynamics : seq&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;int&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Error: Specified method &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;is&lt;/span&gt;&lt;span style="color:#000000;"&gt; not supported.                   &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The previous example of using IDictionary/IDictionary&amp;lt;’Key,’Value&amp;gt;, however, does work in this scenario.&amp;#160; What about the DynamicObject approach?&amp;#160; As &lt;a href="http://simpable.com/"&gt;Scott Watermasysk&lt;/a&gt; described in his post on &lt;a href="http://simpable.com/code/mongodb-dynamics/"&gt;MongoDB and C# Dynamics&lt;/a&gt; it certainly is possible for us to take advantage of a DynamicObject with TryGetMember/TrySetMember defined.&amp;#160; But, how in F# could we take advantage of that?&amp;#160; I hope to cover that soon enough.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;MongoDB has been a great source of inspiration for me lately as I look at Not Only SQL solutions.&amp;#160; Not having to worry about migrations, schemas, data types and the likes, I’ve been able to be quite productive in prototyping ideas, and getting answers quickly.&amp;#160; In addition, with a language such as F# where we can instantly get feedback through our REPL, it adds another dimension to trying out new solutions.&amp;#160; &lt;/p&gt;

&lt;p&gt;With the flexibility of the F# language, we’re able to get some sort of syntactic sugar which allows us to make MongoDB look and feel much like we’re in LINQ to SQL without even the need for the dynamic bindings that are coming in .NET 4.0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=624081" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/ZkxqzVTAU5o" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/NOSQL/default.aspx">NOSQL</category><feedburner:origLink>http://codebetter.com/blogs/matthew.podwysocki/archive/2010/02/09/exploring-mongodb-with-f.aspx</feedburner:origLink></item><item><title>Using and Abusing the F# Dynamic Lookup Operator</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/_9fwNdqFA_w/using-and-abusing-the-f-dynamic-lookup-operator.aspx</link><pubDate>Fri, 05 Feb 2010 21:18:56 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:623767</guid><dc:creator>Matthew.Podwysocki</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Lately, I’ve been playing with such things as MongoDB using F# to rapidly prototype ideas.&amp;#160; With that, I’ve tried to rid myself of magic strings by using the F# dynamic lookup operator.&amp;#160; I’ll cover exactly what I’m doing in the next post when using MongoDB, but in this post I’d like to explore a little of what you could do with a little noticed dynamic lookup operator in F#.&lt;/p&gt;  &lt;h2&gt;The Dynamic Lookup Operator&lt;/h2&gt;  &lt;p&gt;Much like C# 4.0 has the ability to do dynamic lookup, F# also has the same capability, although in a different capacity.&amp;#160; The language has support for a dynamic lookup get operator ( ? ) and set operator ( ?&amp;lt;- ), but note that I said support and not actual implementation.&amp;#160; The actual implementation is up to you and how you want to use it.&amp;#160; &lt;/p&gt;  &lt;h2&gt;The Get Operator&lt;/h2&gt;  &lt;p&gt;Let’s start off by implementing the get operator to get a public property (not super useful yet).&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:866fcd2f-0579-4d30-a2c8-9103e524a6ce" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (this : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Source) (prop : string) : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Result &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; p &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.GetType().GetProperty(prop)
  p.GetValue(this, &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;null&lt;/span&gt;&lt;span style="color:#000000;"&gt;) :&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Result&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can write an example that verifies the behavior such as comparing a normal invocation and our “dynamic” invocation, as in this example of comparing getting the length of a string.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:dc44dbe9-352b-48c4-869a-d44ecf4dfe20" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#000000;"&gt;[&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Fact&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ``Dynamic lookup should equal normal``() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  areEqual &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;foo&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;.Length &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;foo&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Length&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;But, we’re not limited to that.&amp;#160; For example, we could instead decide that we want to get a private member instead of a public one.&amp;#160; We could change up our example from above just slightly.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:4bbc102d-96c9-4aef-bc69-492668756c70" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (this : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Source) (prop : string) : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Result &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; flags &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; BindingFlags.GetProperty &lt;/span&gt;&lt;span style="color:#000000;"&gt;|||&lt;/span&gt;&lt;span style="color:#000000;"&gt;
              BindingFlags.NonPublic
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; p &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.GetType().GetProperty(prop, flags)
  p.GetValue(this, &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;null&lt;/span&gt;&lt;span style="color:#000000;"&gt;) :&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Result&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can verify our behavior of this idea with a little example, for example invoking a private property in a custom class such as the following:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:4a86731b-00e8-440d-9bf7-ef1e3a7ba6e9" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; PrivateProperty(propValue : &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt; __.PropValue
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;with&lt;/span&gt;&lt;span style="color:#000000;"&gt; get() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; propValue
    
[&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Fact&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ``Can invoke &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt; property``() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; expected &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;foo&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; p &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; PrivateProperty(expected)
  
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; actual : &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; p&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;PropValue
  
  areEqual expected actual&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So, as you can see, this is quite useful so far, but we’ve only scratched the surface.&amp;#160; We’ve just dealt with properties so far, but what about methods?&amp;#160; The same applies here as well.&amp;#160; In this instance, let’s take a method that could have any number of arguments and invoke it just as if we would normally.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:05538349-00e3-4542-854e-32411c303680" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;open&lt;/span&gt;&lt;span style="color:#000000;"&gt; Microsoft.FSharp.Reflection
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;open&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.Reflection

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (this : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Source) (member&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt; : &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (args : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Args) : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Result &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; argArray &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; box args &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;null&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;then&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;null&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;elif&lt;/span&gt;&lt;span style="color:#000000;"&gt; FSharpType.IsTuple (args.GetType()) &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;then&lt;/span&gt;&lt;span style="color:#000000;"&gt;
      FSharpValue.GetTupleFields args
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;else&lt;/span&gt;&lt;span style="color:#000000;"&gt; [&lt;/span&gt;&lt;span style="color:#000000;"&gt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt;args&lt;/span&gt;&lt;span style="color:#000000;"&gt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt;]

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; flags &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; BindingFlags.GetProperty &lt;/span&gt;&lt;span style="color:#000000;"&gt;|||&lt;/span&gt;&lt;span style="color:#000000;"&gt; BindingFlags.InvokeMethod
  this.GetType().InvokeMember(&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;, flags, null, this, argArray) :?&amp;gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Result&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What we needed to do here is take not only the member but the arguments as well.&amp;#160; If the arguments object is null (or unit), then we pass a null objet array, else if our type is a tuple, then we create an array from our tuple, and finally if it’s a single argument, then we make it into an array.&amp;#160; Finally we invoke our member with the flags to say it is either a property getter or a method and invoke with our arguments.&amp;#160; Let’s write an example of how to use this.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:01861c9c-0771-4398-984e-000b556fa5eb" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#000000;"&gt;[&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Fact&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ``Can invoke method &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;with&lt;/span&gt;&lt;span style="color:#000000;"&gt; dynamic lookup``() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  isTrue (&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;dynamic&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Length() &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#000000;"&gt;)
  isTrue (&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;dynamic&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;EndsWith(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;ic&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;))
  areEqual &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;dyn&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;dynamic&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Substring(&lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;/span&gt;&lt;span style="color:#800080;"&gt;3&lt;/span&gt;&lt;span style="color:#000000;"&gt;))&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Above are three tests which show no arguments, a single argument, and finally tupled arguments.&amp;#160; But what about setters?&lt;/p&gt;

&lt;h2&gt;The Set Operator&lt;/h2&gt;

&lt;p&gt;Just as we have the ( ? ) operator reserved for the get operator, we have the ( ?&amp;lt;- ) operator reserved for the set.&amp;#160; This allows us to be able to set any number of things with the same ease as the get.&amp;#160; For example, we could set a public property:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:38511071-584c-4999-9bdf-609e8675bccf" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (this : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Source) (property : string) (value : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Value) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  this.GetType().GetProperty(property).SetValue(this, value, &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;null&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This simply gets the property and then sets the appropriate value.&amp;#160; And then we can write a test as an example of how it should work.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:bdcb239e-239d-4993-ad5d-025aa0912a71" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; MutablePropertyClass(value : &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; mutable v &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; value
  
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; __.Value 
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;with&lt;/span&gt;&lt;span style="color:#000000;"&gt; get() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; v
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;and&lt;/span&gt;&lt;span style="color:#000000;"&gt;  set(value) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; v &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; value
    
[&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Fact&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]    
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ``Dynamic setter should set property``() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;    
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; m &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; MutablePropertyClass(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;foo&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)
  
  m&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;Value &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;dynamic&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  
  areEqual &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;dynamic&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; m.Value&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In this example, we have a simple class with a property with a getter and setter and then we set our property using our special operator and then compare the values.&amp;#160; Once again, this is flexible enough where we could set private properties much as we retrieved them above.&amp;#160; Now, let’s put them together for a few quick examples.&lt;/p&gt;

&lt;h2&gt;The Dictionary Example&lt;/h2&gt;

&lt;p&gt;One idea that we could go with is instead of using string keys for dealing with key value pairs, we could use our dynamic getter and setter instead.&amp;#160; Nothing like a bit of syntactic sugar to brighten your day to lessen the noise.&amp;#160; Our goal for this is to go from:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c551252a-4065-49d9-af17-691761e97d78" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; d &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Dictionary&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;,obj&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;()
d.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;StaticKey&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Meh&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To something like the following:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:28d23b49-0389-4130-ad7a-efef103ec786" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; d &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Dictionary&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;,obj&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;()
d&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;DynamicKey &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Totally!&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;How could we pull this one off?&amp;#160; Well, we could implement the dynamic lookup getter and setter to do nothing more than look in the dictionary as follows:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:ccc253e8-5da9-4806-9b84-76b4049a1b0c" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;open&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.Collections

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (this : #IDictionary) key &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  this.[key]

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt;) (this : #IDictionary) key value &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  this.[key] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; value&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we can verify our behavior with our test that we should have written first.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f4bc3bfc-bf18-40c6-9743-4dc6835c2245" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ``Dictionary should get &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;and&lt;/span&gt;&lt;span style="color:#000000;"&gt; set dynamically``() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; d &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Dictionary&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;,obj&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;()
  
  d&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;DynamicKey &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;hello&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  
  areEqual d.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;DynamicKey&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;] d&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;DynamicKey&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;A solution like this could work well for situations like MongoDB, which we’ll get into with our next post.&amp;#160; But, could go a step further and to say anything with the Item property could be ours for the taking.&lt;/p&gt;

&lt;h2&gt;The Item Indexer Property Example&lt;/h2&gt;

&lt;p&gt;In the .NET libraries, we have a few classes which expose an indexer property like an array, a Dictionary, and even a string.&amp;#160; It would be nice to have a way to both get and set this value through the use of our dynamic lookup operator, but how could we pull this off?&amp;#160; In some previous posts, I talked about generic restrictions in the F# language, and one in particular stands out, the member restriction operator.&amp;#160; This operators lets us constrain a given object parameter so that it must implement the following methods and properties.&lt;/p&gt;

&lt;p&gt;Remember, our overall goal is to support calling this:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:ef4295f5-72b3-4783-8021-4efb018ebb1e" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;open&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.Collections.Generic

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; d &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Dictionary&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;()
d&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;DynamicKey &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Totally!&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; IndexedObject() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; d &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Dictionary&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;()

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; self.Item
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;with&lt;/span&gt;&lt;span style="color:#000000;"&gt; get(key) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
      d.[key]
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;and&lt;/span&gt;&lt;span style="color:#000000;"&gt; set key value &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
      d.[key] &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; value
      
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; i &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; IndexedObject()
h&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;IndexedKey &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;IndexedValue&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So, what we have is both a Dictionary&amp;lt;TKey,TValue&amp;gt; and a custom indexed object.&amp;#160; Since they do not follow an inheritance chain which exposes an Item property, we cannot use the example from above with the IDictionary.&amp;#160; Instead, we’ll use member restrictions for both the method get_Item and set_Item.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:0b7b33dc-3edc-4d42-9c57-fca6201921c3" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;inline&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;) this key &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  ( &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;a : (&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; get_Item : &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;b &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;c) (this,key))
 
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;inline&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt;) this key value &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  ( &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;a : (&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; set_Item : &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;b &lt;/span&gt;&lt;span style="color:#000000;"&gt;*&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;c &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;^&lt;/span&gt;&lt;span style="color:#000000;"&gt;d) (this,key,value))&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What you see is that we’re calling both the get_Item and set_Item properties, which are the raw method names for the Item property.&amp;#160; Now we’re able to verify our test using our IndexedObject class from above:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:32c3c653-566b-4294-9d38-e85d0f9486a8" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ``Can &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;use&lt;/span&gt;&lt;span style="color:#000000;"&gt; dynamic indexed getter &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;and&lt;/span&gt;&lt;span style="color:#000000;"&gt; setter``() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; i &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; IndexedObject()
  
  i&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;SomeKey &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Some value&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  
  areEqual i.[&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;SomeKey&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;] i&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;SomeKey&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A big word of caution&lt;/em&gt;&lt;/strong&gt; when using this approach is that you’ll get a nice warning from the F# compiler that doing this may cause unverified code as F# treats the Item property specially.&amp;#160; For example, all value types must be boxed before putting them into the collection.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c176f261-ae1d-4739-9adc-e64ea832b937" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; h &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Hashtable()
h&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;MyKey &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;3&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Don&amp;#39;t do this&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;
h&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&lt;/span&gt;&lt;span style="color:#000000;"&gt;MyKey &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;-&lt;/span&gt;&lt;span style="color:#000000;"&gt; box &lt;/span&gt;&lt;span style="color:#800080;"&gt;3&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Do this&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Very powerful way of doing things but also you must be careful with this approach if you use it at all.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;So, as you can see, F#, just like C# has the facilities for dynamic lookup, although in F# you are left to implement it yourself in any which way you like.&amp;#160; One great thing about these operator is that it doesn’t require .NET 4.0 to implement and use them.&amp;#160; But with any power comes of course some responsibility for it, so use it wisely. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=623767" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/_9fwNdqFA_w" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/F_2300_/default.aspx">F#</category><feedburner:origLink>http://codebetter.com/blogs/matthew.podwysocki/archive/2010/02/05/using-and-abusing-the-f-dynamic-lookup-operator.aspx</feedburner:origLink></item><item><title>Scoop: Reflector v6 pro RTM to be released by the 15th of this month</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/GB5m9DdUq9E/reflector-v6-pro-to-be-released-by-mid-february.aspx</link><pubDate>Fri, 05 Feb 2010 15:38:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:623732</guid><dc:creator>Patrick Smacchia</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;This is really exciting time these days. Most of .NET tooling vendors are about to provide a major upgrade of their products within the next weeks. And &lt;a target="_blank" href="http://www.red-gate.com/products/reflector/"&gt;Reflector&lt;/a&gt; is part of the lot! &lt;b&gt;A brand new version, Reflector v6, is about to be go live RTM on Monday 15th of February 2010&lt;/b&gt;. This will be the first time the company &lt;a target="_blank" href="http://www.red-gate.com"&gt;Red-Gate&lt;/a&gt; will update the product since it has been acquired from its original creator, &lt;a target="_blank" href="http://www.lutzroeder.com/"&gt;Lutz Roeder&lt;/a&gt;, in August 2008.&lt;/p&gt;
&lt;p&gt;There are 90% of chances you are using Reflector daily so don&amp;#39;t be afraid: current Reflector features will continue to be provided in a free version of the tool. The Red-Gate strategy is to append new innovative features to the tool, and only these features will require a professional purchased version. The flagships features of Reflector v6 is &lt;b&gt;the ability to debug source code decompiled from IL code, in the Visual Studio debugger. &lt;/b&gt;This is certainly a killer one: we &lt;b&gt;all &lt;/b&gt;need at a point to have a better understanding of what&amp;#39;s happening at runtime in Framework used by our code.&lt;/p&gt;
&lt;p&gt;Having used Reflector v6 beta, I can say that plenty of cool featurettes have been also been added, including a bridge between Reflector and Visual Studio (ok this one is already provided more or less by several tools, including &lt;a target="_blank" href="http://www.testdriven.net/"&gt;TestDriven.NET&lt;/a&gt; and &lt;a target="_blank" href="http://codebetter.com/controlpanel/blogs/posteditor.aspx/www.NDepend.com"&gt;NDepend&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Another cool thing is that the upcoming &lt;a target="_blank" href="http://www.ndepend.com/Version3BetaProgram.aspx"&gt;NDepend v3&lt;/a&gt; is working hand-in-hand with Reflector v6 (as a Reflector addin). And as NDepend v3 is also a Visual Studio 2010 / 2008 /2005 addin, all NDepend features constitute more glue between Reflector v6 and Visual Studio, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;from Reflector to Visual Studio
&lt;ul&gt;
&lt;li&gt;Generating dependency graph and dependency matrix&lt;/li&gt;
&lt;li&gt;Generating &lt;a target="_blank" href="http://www.ndepend.com/Features.aspx#CQL"&gt;CQL queries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Opening Source files definition&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;from Visual Studio to Reflecor
&lt;ul&gt;
&lt;li&gt;Opening a code element (assembly, namespace, type, method, field) in the Reflector class browser &lt;/li&gt;
&lt;li&gt;Decompiling a code element in a source file in any language supported by Reflector (IL, C#, VB.NET, MC++I, Oxygen, Delphi)&lt;/li&gt;
&lt;li&gt;Decompiling an older and a newer version of a code element in 2 text files, and comparing the 2 text files with your preferred &lt;a target="_blank" href="http://codebetter.com/blogs/patricksmacchia/archive/2008/04/28/diff-tools-to-see-source-files-changes.aspx"&gt;diff tool&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.Reflector6/NDependToReflector6.jpg"&gt;&lt;img src="http://codebetter.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.Reflector6/NDependToReflector6.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=623732" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/GB5m9DdUq9E" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/patricksmacchia/archive/2010/02/05/reflector-v6-pro-to-be-released-by-mid-february.aspx</feedburner:origLink></item><item><title>StructureMap 2.6 (and 2.5.4) is Released!</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/UCex2CnUvcc/structuremap-2-6-and-2-5-4-is-released.aspx</link><pubDate>Thu, 04 Feb 2010 15:14:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:619980</guid><dc:creator>Jeremy D. Miller</dc:creator><slash:comments>20</slash:comments><description>&lt;p&gt;Time flies when you&amp;rsquo;re having fun.&amp;nbsp; It&amp;rsquo;s been almost a year since I&amp;rsquo;ve made an official StructureMap release, so I guess it&amp;rsquo;s about time.&amp;nbsp; This morning I uploaded &lt;a href="https://sourceforge.net/projects/structuremap/files/"&gt;the binaries for the 2.6 release&lt;/a&gt;.&amp;nbsp; This release just adds some bug fixes and a couple minor additions to the 2.5.4 release that I made in December but didn&amp;rsquo;t really publicize.&amp;nbsp; The release notes below are long, but that&amp;rsquo;s because they represent almost a year&amp;rsquo;s worth of development.&amp;nbsp; As I said yesterday, StructureMap is most likely moving to GitHub with the documentation going as well.&amp;nbsp; After a massive effort to write documentation early last year, huge chunks of it is already obsolete and there&amp;rsquo;s been a lot of addition since.&amp;nbsp; I&amp;rsquo;m hoping that the move to the Wiki will make it easier to keep the docs up.&amp;nbsp; In the meantime, I&amp;rsquo;ll try to blog a bit about the newer pieces starting tomorrow.&lt;/p&gt;
&lt;p&gt;A tiny bit of history.&amp;nbsp; This is the 11th StructureMap release since it debuted way back in June of 2004.&amp;nbsp; Almost nothing is the same.&amp;nbsp; We use it differently, the expectations are different, and very, very little of the original code survives today.&amp;nbsp; At QCon San Francisco in 2008 I talked about &lt;a href="http://www.infoq.com/presentations/Lessons-Learned-Jeremy-Miller"&gt;what I&amp;rsquo;d learned&lt;/a&gt; from evolving this codebase over so many years and changes.&lt;/p&gt;
&lt;p&gt;This release includes a lot of patches from the community, and I&amp;rsquo;d like to thank all of you for that &amp;ndash; especially Frank Quednau and Andreas Ohlund for taking on some nastier things.&amp;nbsp; Josh and Kevin Miller do yeoman duty answering StackOverflow questions (so I don&amp;rsquo;t have to).&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;&lt;b&gt;What&amp;rsquo;s Changed?&lt;/b&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;New terse, &amp;ldquo;jQuery-esque&amp;rdquo; syntax for the Registry DSL.&amp;nbsp; Let&amp;rsquo;s just write off &amp;ldquo;ForRequestedType&amp;lt;IFoo&amp;gt;().TheDefault.Is.OfConcreteType&amp;lt;Foo&amp;gt;()&amp;rdquo; as a well meant experiment, shall we?&amp;nbsp; It&amp;rsquo;s still in the codebase, but it&amp;rsquo;s marked as [Obsolete].&amp;nbsp; Nobody liked it and I thought it was annoying in real life usage.&amp;nbsp; Now, just do:&amp;nbsp; For&amp;lt;IFoo&amp;gt;().Use&amp;lt;Foo&amp;gt;();&amp;nbsp; My whole goal was to reduce friction.&amp;nbsp; Needs a big blog post&lt;/li&gt;
&lt;li&gt;Changed the Registry DSL to make inline dependency configuration be more consistent.&amp;nbsp; Definitely a blog post.&lt;/li&gt;
&lt;li&gt;The &amp;ldquo;CreateProfile&amp;rdquo; syntax has gotten a lot of complaints for being inconsistent with the rest of the Registry DSL.&amp;nbsp; I basically rewrote it to now be consistent with the &amp;ldquo;For&amp;lt;&amp;gt;().Use()&amp;rdquo; syntax in the main Registry DSL.&amp;nbsp; Blog post coming soon&amp;hellip;.&lt;/li&gt;
&lt;li&gt;Nested Container feature for short lived transactional requests.&amp;nbsp; I built this for Dovetail usage, but I think it&amp;rsquo;s my preferred way to manage object scoping in certain circumstances.&amp;nbsp; I mentioned it just a little bit in my &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2010/01/06/how-dovetail-uses-structuremap-with-nhibernate.aspx"&gt;NHibernate w/ StructureMap&lt;/a&gt; post a couple weeks back.&amp;nbsp; Blog post coming soon&amp;hellip;&lt;/li&gt;
&lt;li&gt;The &amp;ldquo;Model&amp;rdquo; feature was completely redone.&amp;nbsp; There&amp;rsquo;s a lot more power, and you can use it to pull services out of the Container and completely remove services from the Container as well.&amp;nbsp; Sigh.&amp;nbsp; Needs a blog post.&lt;/li&gt;
&lt;li&gt;Convention based type registration got a lot of work.&amp;nbsp; People are pushing this feature very hard and it had to grow.&amp;nbsp; You can now use the Registry DSL to write conventions.&amp;nbsp; This was improved farther in the latest code drop.&amp;nbsp; Yeah, blog post coming&amp;hellip;&lt;/li&gt;
&lt;li&gt;Better support for registering services by Type objects for cases when you don&amp;rsquo;t necessarily know the Type upfront.&amp;nbsp; Big request from several framework authors like &lt;a href="http://www.codeplex.com/caliburn"&gt;Caliburn&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A helluva lot of new features to make working with open generic types easier.&amp;nbsp; Jimmy Bogard &lt;a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/12/17/advanced-structuremap-connecting-implementations-to-open-generic-types.aspx"&gt;blogged about some of it here&lt;/a&gt;.&amp;nbsp; I&amp;rsquo;d like to show how StructureMap&amp;rsquo;s new features would make writing something like Davy Brion&amp;rsquo;s &lt;a href="http://davybrion.com/blog/category/agatha/"&gt;Agatha framework&lt;/a&gt; a snap.&amp;nbsp; I use this stuff extensively inside of StoryTeller.&lt;/li&gt;
&lt;li&gt;Added the lazy Func&amp;lt;T&amp;gt; feature from Autofac.&amp;nbsp; A really great (and cheap) way to support lazily initialized components.&amp;nbsp; Blog post coming.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Completely ditched all Reflection.Emit code&lt;/b&gt;.&amp;nbsp; StructureMap now strictly uses dynamically constructed Expression&amp;rsquo;s that are pre-compiled into cached Func&amp;rsquo;s.&amp;nbsp; I don&amp;rsquo;t know if that really makes much difference to users, but it makes StructureMap much, much easier to extend.&amp;nbsp; The container does spin up faster with this mechanism.&amp;nbsp; Makes &lt;b&gt;me&lt;/b&gt; happy.&lt;/li&gt;
&lt;li&gt;Supports IList&amp;lt;T&amp;gt; and List&amp;lt;T&amp;gt; arguments.&amp;nbsp; It works just like Arrays.&amp;nbsp; That&amp;rsquo;s been a while coming.&lt;/li&gt;
&lt;li&gt;You can set the lifecycle from &amp;lt;AddInstance&amp;gt; if you happen to still use Xml configuration.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;The &amp;ldquo;Lifecycle&amp;rdquo; code was completely reworked to eliminate shared code&lt;/li&gt;
&lt;li&gt;Container.Dispose() was introduced.&amp;nbsp; I&amp;rsquo;ve put a lot of effort into making StructureMap clean up after itself.&amp;nbsp; Definitely a blog post coming.&lt;/li&gt;
&lt;li&gt;ObjectFactory.Container.&amp;nbsp; Slowly, but surely, I&amp;rsquo;d like to wean people away from using ObjectFactory too much in favor of scoped Container objects.&amp;nbsp; I will NOT be further extending the ObjectFactory static methods to synchronize it with IContainer.&amp;nbsp; Instead, I&amp;rsquo;m just exposing the ObjectFactory.Container property.&lt;/li&gt;
&lt;li&gt;New abilities for IContext like BuildUp() (thanks to Kyle Malloy), getting all instances, and TryGetInstance&lt;/li&gt;
&lt;li&gt;TryGetInstance() from Josh&lt;/li&gt;
&lt;li&gt;Killed StructureMapConfiguration.&amp;nbsp; Good riddance.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Forwarding&amp;rdquo; requests for IFoo to whatever IBar is&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=619980" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/UCex2CnUvcc" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/jeremy.miller/archive/tags/StructureMap/default.aspx">StructureMap</category><feedburner:origLink>http://codebetter.com/blogs/jeremy.miller/archive/2010/02/04/structuremap-2-6-and-2-5-4-is-released.aspx</feedburner:origLink></item><item><title>Business Primitives (2/2)</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/RpyosKcZoVQ/business-primitives-2-2.aspx</link><pubDate>Thu, 04 Feb 2010 11:18:50 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:618342</guid><dc:creator>drusellers</dc:creator><slash:comments>10</slash:comments><description>&lt;p&gt;
Ok, so now that we have talked about the Business Primitive concept lets go through some of the actual examples. Let&amp;#39;s take an example of a &amp;#39;Loan&amp;#39; class.
&lt;/p&gt;

&lt;pre&gt;
public class Loan
{
    public int Id { get; set; }
    public int InterestRate { get; set; }
    public DateTime TradedOn { get; set; }
    public DateTime SettledOn { get; set; }
    public decimal Principal { get; set; } 
}
&lt;/pre&gt;

&lt;p&gt;
After some small tweaks.
&lt;/p&gt;

&lt;pre&gt;
public class Loan
{
    public int Id { get; set; }
    public Rate Interest { get; set; }
    public DateTime TradedOn { get; set; }
    public DateTime SettledOn { get; set; }
    public Money Principal { get; set; }
}
&lt;/pre&gt;

&lt;p&gt;Already the code feels more robust to me. The dates aren&amp;#39;t that interesting to the business other than they are dates so they haven&amp;#39;t yet been uplifted into &amp;#39;business primitives&amp;#39; but Interest has been converted to &amp;#39;Rate&amp;#39;, which immediately helps with math and providing meaningful math like methods, as well as Principal which is now &amp;#39;Money&amp;#39; which also helps with math and the more pernicious rounding issues.
&lt;/p&gt;

&lt;p&gt;
So how was &amp;#39;Rate&amp;#39; implemented? What does it look like?
&lt;p&gt;

&lt;pre&gt;
[DebuggerDisplay(&amp;quot;{_rate}%&amp;quot;)]
public class Rate
{
    int _rate;
    private Rate() { }
    
    //factory methods
    public static Rate FromWholePercent(int rate) { new Rate(){_rate = rate};}

    //equality overrides here
    //operator overrides here
} 
&lt;/pre&gt;

&lt;p&gt;
First, we have the &amp;#39;DebuggerDisplay&amp;#39; attribute which is my new best friend, it allows you to customize how the debugger displays your object in the debug view, very helpful.  I have wrapped the previous rate value in a very simple fashion, and now we have a nicely centralized place to put math based functions (myRate = baseRate+riskRate). I have also added a factory method that help explain how this Rate object is being made. From whole percents such as 78% or 22%. Because we have hidden the way we actually store the value, we could also add support for 22.2% by adding a new factory method and changing the internal storage with out changing any other part of the code base. Very cool.
&lt;/p&gt;

&lt;p&gt;Ok, so what about saving these value objects and now I need to bind them to the UI how do I get at that hidden variable? I have taken quite a few paths when trying to implement this and the way that I do things now is a combination interface + base class. If you are anything like me you are thinking &amp;#39;base class, yuck&amp;#39; and well I still do but this is the best way that I have come up with and I am open for suggestions. :)&lt;/p&gt;

&lt;p&gt;
So my &amp;#39;business primitives&amp;#39; inherit from an abstract class called &amp;#39;Primitive&amp;lt;T&amp;gt;&amp;#39; this class helps to streamline the creation of my business primitives. It also EXPLICITLY implements an interface called ValueObject&amp;lt;T&amp;gt; that exposes the underlying value, that can be used by UI controls and persistance frameworks with out mucking up my public API. I love that I don&amp;#39;t see &amp;#39;SetValue&amp;#39; and &amp;#39;GetValue&amp;#39; unless I want to (yes, this could have been a property, not sure why I choose this). Here is the interface:
&lt;/p&gt;

&lt;pre&gt;
public interface ValueObject&amp;lt;T&amp;gt;
{
    void SetValue(T input);
    T GetValue();
}
&lt;/pre&gt;

&lt;p&gt;and the base class&lt;/p&gt;

&lt;pre&gt;
[DebuggerDisploy(&amp;quot;{_primitiveValue}&amp;quot;)]
public class Primitive&amp;lt;T&amp;gt; :
    ValueObject&amp;lt;T&amp;gt;
{
    T _primitiveValue;

    public Primitive()
    {
    }

    public Primitive(V primitiveValue)
    {
        _primitiveValue = primitiveValue;
    }

    void ValueObject&amp;lt;T&amp;gt;.SetValue(T input)
    {
       _primitiveValue = input;
    }

    T ValueObject.GetValue()
    {
        return _primitiveValue;
    }
        
    //equality stuff
}
&lt;/pre&gt;

&lt;p&gt;I really wanted to do some tricky generics to try and implement the operator overloads in the base class as well, but the compiler wasn&amp;#39;t to happy about that so those still have to be implemented in the &amp;#39;Rate&amp;#39; class. Now my &amp;#39;Rate&amp;#39; object looks like this:&lt;/p&gt;

&lt;pre&gt;
public class Rate :
    Primitive&amp;lt;int&amp;gt;
{
    private Rate() { }
    private Rate(int value) : base(value){}

    //factory methods
    public static Rate FromWholePercent(int rate) { new Rate(rate);}

    //operator overloads should be implemented here

    public bool Equals(Rate other)
    {
        if (ReferenceEquals(null, other)) return false;
        if (ReferenceEquals(this, other)) return true;
        return base.Equals(other);
    }
} 
&lt;/pre&gt;

&lt;p&gt;For saving these buggers? Well, using NHibernate we can persist this as an &amp;#39;int&amp;#39; using an IUserType, which makes things very simple and still manages to keep NH out of our domain.&lt;br /&gt;
&lt;strong&gt;Some links on implementing IUserTypes&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.lostechies.com/blogs/rhouston/archive/2008/03/23/mapping-strings-to-booleans-using-nhibernate-s-iusertype.aspx"&gt;A good example of the IUserType implementation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://geekswithblogs.net/opiesblog/archive/2006/08/13/87880.aspx"&gt;Generic IUserType&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://wiki.fluentnhibernate.org/Available_conventions"&gt;In FluentNHibernate check out the &amp;#39;UserTypeConvention&amp;#39;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

Otherwise, with the interface you now have the means to get access to the value, so customize for your needs!
&lt;/p&gt;

&lt;p&gt;Now that we have addressed the saving aspect, what&amp;#39;s a good way to present these &amp;#39;business primitives&amp;#39;? Because
&lt;pre&gt;
inputLoanPrincipal.Text = loan.Principal.ToUiString();
&lt;/pre&gt;
sucks. I would suggest some extension methods on your UI controls that take Primitive&amp;lt;T&amp;gt; as the type and can then cast to the ValueObject and get access to the value. Or extending the UI binding much in the way FubuMVC has, seems like a really solid way to &lt;a href="http://groups.google.com/group/fubumvc-devel/browse_thread/thread/e54095b2ad5f81f8/669a4155b0f6b914?lnk=gst#669a4155b0f6b914"&gt;approach&lt;/a&gt; things too.
&lt;/p&gt;

&lt;p&gt;I hope this helps :)&lt;p&gt;
-d
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=618342" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/RpyosKcZoVQ" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/dru.sellers/archive/tags/Small+Ideas/default.aspx">Small Ideas</category><feedburner:origLink>http://codebetter.com/blogs/dru.sellers/archive/2010/02/04/business-primitives-2-2.aspx</feedburner:origLink></item><item><title>Getting StructureMap off SourceForge, Thoughts?</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/oW6-w2Kt_fM/getting-structuremap-off-sourceforge-thoughts.aspx</link><pubDate>Wed, 03 Feb 2010 22:29:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:618163</guid><dc:creator>Jeremy D. Miller</dc:creator><slash:comments>22</slash:comments><description>&lt;p&gt;The original discussion for this topic is here:&amp;nbsp; http://groups.google.com/group/structuremap-users/browse_thread/thread/6d579f4e9b508c66&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;All,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve never liked SourceForge and it&amp;#39;s a PITA for me to use even though it&amp;#39;s gotten better over the years. &amp;nbsp;I&amp;#39;d like &lt;br /&gt; to move StructureMap off SourceForge and more importantly, get a real &lt;br /&gt; Wiki site up so that we have at least a fighting chance of keeping the &lt;br /&gt; documentation up to date. &amp;nbsp;On the other hand, I get a significant &lt;br /&gt; number of patches from you guys (thanks for that) and I&amp;#39;d also like a &lt;br /&gt; better way of handling those submissions -- and making it easier for &lt;br /&gt; *you* to get involved.&lt;/p&gt;
&lt;p&gt;Right now, Josh and I are thinking about moving StructureMap to GitHub &lt;br /&gt; (you knew that was coming) and trying to use the Wiki support on &lt;br /&gt; Github for now. &amp;nbsp;Granted, Git is weird as hell for those of us used to &lt;br /&gt; SVN, but GitHub has some huge advantages for OSS community &lt;br /&gt; development. &amp;nbsp;I&amp;#39;d *love* to start managing StructureMap patches &lt;br /&gt; through GitHub &amp;quot;pull&amp;quot; requests (or whatever the correct lingo is).&lt;/p&gt;
&lt;p&gt;Any thoughts? &amp;nbsp;Volunteers? ;)&lt;/p&gt;
&lt;p&gt;Jeremy &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=618163" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/oW6-w2Kt_fM" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/jeremy.miller/archive/tags/StructureMap/default.aspx">StructureMap</category><feedburner:origLink>http://codebetter.com/blogs/jeremy.miller/archive/2010/02/03/getting-structuremap-off-sourceforge-thoughts.aspx</feedburner:origLink></item><item><title>An introduction to iptables</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/rHaPF71cZnU/an-introduction-to-iptables.aspx</link><pubDate>Wed, 03 Feb 2010 14:36:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:618149</guid><dc:creator>karl</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;iptables is a linux application that allows you to configure the built-in linux firewall. There are abstraction layers built on top of it, including nice GUIs, but I recently had some very basic rules I wanted to implement, and figured I&amp;#39;d learn how to do it directly in iptables. It turned out to be easy to configure, and I thought I&amp;#39;d give a very basic introduction.&lt;/p&gt;
&lt;p&gt;First though, I relied on the ubuntu documentation to get up and running (&lt;a href="https://help.ubuntu.com/community/IptablesHowTo"&gt;https://help.ubuntu.com/community/IptablesHowTo&lt;/a&gt;). I&amp;#39;ll pretty much just regurgitate what&amp;#39;s in there - I&amp;#39;ve said it before, stop believing that linux documentation is written only for people who already know linux. Also, depending on your setup, most of these commands might require elevation (sudo).&lt;/p&gt;
&lt;p&gt;By default, iptables defines three rule chains: &lt;code&gt;INPUT&lt;/code&gt;, &lt;code&gt;FORWARD&lt;/code&gt; and &lt;code&gt;OUTPUT&lt;/code&gt;. We&amp;#39;ll only concern ourselves with &lt;code&gt;INPUT&lt;/code&gt; - namely the chain used for incoming packets directed at this particular machine. At any point, you can list the rules by entering &lt;code&gt;iptables -L&lt;/code&gt;. If listing the rules turns out to be really slow, try using &lt;code&gt;iptables -L -n&lt;/code&gt;. The &lt;code&gt;-n&lt;/code&gt; option means that the display will output IP addresses and ports in numeric format, without trying to do a DNS lookup. If the &lt;code&gt;-n&lt;/code&gt; option makes it fast, then you&amp;#39;re system likely has incorrect DNS settings (you can check out &lt;a href="http://www.cyberciti.biz/tips/linux-how-to-setup-as-dns-client.html"&gt;http://www.cyberciti.biz/tips/linux-how-to-setup-as-dns-client.html&lt;/a&gt; for help with that).&lt;/p&gt;
&lt;p&gt;In my particular case, the server is has two network interfaces - a public facing one (on &lt;code&gt;eth0&lt;/code&gt;) and a private one (on &lt;code&gt;eth1&lt;/code&gt;). For my purposes, I want to remotely (&lt;code&gt;eth0&lt;/code&gt;) access SSH from my static IP, and locally (&lt;code&gt;eth1&lt;/code&gt;) access postgresql on port 5432.&lt;/p&gt;
&lt;p&gt;To accomplish this we simply append two rules to the INPUT chain:&lt;/p&gt;
&lt;pre&gt;iptables -A INPUT -p tcp --dport ssh -s 205.38.19.199 -i eth0 -j ACCEPT
iptables -A INPUT -p tcp --dport 5432 -i eth1 -j ACCEPT&lt;/pre&gt;
&lt;p&gt;The first rule appends itself to the &lt;code&gt;INPUT&lt;/code&gt; chain. Its limited to the &lt;code&gt;TCP&lt;/code&gt; protocol targeting the &lt;code&gt;SSH&lt;/code&gt; port (22) with a source originating from &lt;code&gt;205.38.19.199&lt;/code&gt; on the &lt;code&gt;eth0&lt;/code&gt; network interface. It jumps to an &lt;code&gt;ACCEPT&lt;/code&gt; status (all other processing stops). The next rule is similar, except it allows any source so long as they are connected to &lt;code&gt;eth0&lt;/code&gt; and targeting port &lt;code&gt;5432&lt;/code&gt; (over &lt;code&gt;tcp&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;We can now add a third rule to block all other access:&lt;/p&gt;
&lt;pre&gt;iptables -A INPUT -j DROP&lt;/pre&gt;
&lt;p&gt;if incoming traffic doesn&amp;#39;t mean the first two criteria, we&amp;#39;ll hit this third rule and the firewall will reject the connection.&lt;/p&gt;
&lt;p&gt;We&amp;#39;ll run into 1 issue with our above configuration though - we&amp;#39;ve blocked access to the loopback interface (127.0.0.1). We need to add a special rule to allow loopback connections (since a lot of programs rely on it). However, we can&amp;#39;t simply append it as it&amp;#39;ll never be reached. Instead of using &lt;code&gt;-a&lt;/code&gt; to append, we&amp;#39;ll use &lt;code&gt;-i&lt;/code&gt; to insert:&lt;/p&gt;
&lt;pre&gt;iptables -I INPUT 1 -i lo -j ACCEPT&lt;/pre&gt;
&lt;p&gt;Here we are inserting our rule in the 1st position, and accepting all connections made on the special lo (loopback) interface.&lt;/p&gt;
&lt;p&gt;A really neat thing about iptables is that they aren&amp;#39;t persisted by default. So, if you happen to mess up and cut yourself off from your server, a simple reboot will reset everything (hopefully you have access to do a remote reboot from a web interface, or maybe you can just walk up to the machine and reboot it).&lt;/p&gt;
&lt;p&gt;At some point though, you&amp;#39;ll want to make sure your rules are persisted. Achieving this is a two step process. First, you save your rules to a file by using the &lt;code&gt;iptables-save&lt;/code&gt; and redirecting STDOUT to a file:&lt;/p&gt;
&lt;pre&gt;iptables-save &amp;gt; /etc/iptables.rules&lt;/pre&gt;
&lt;p&gt;Second, and this depends on which distro you have but on debian/ubuntu, you make sure your rules are loaded on startup. Simply edit &lt;code&gt;/etc/network/interfaces&lt;/code&gt;, find your interface, and add:&lt;/p&gt;
&lt;pre&gt;pre-up iptables-restore &amp;lt; /etc/iptables.rules &lt;/pre&gt;
&lt;p&gt;to the list, so that it looks something like:&lt;/p&gt;
&lt;pre&gt;auto eth0
iface eth0 inet static
address xxx
netmask yyy
gateway ddd
pre-up iptables-restore &amp;lt; /etc/iptables.rules&lt;/pre&gt;
&lt;p&gt;That&amp;#39;s it!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=618149" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/rHaPF71cZnU" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/karlseguin/archive/2010/02/03/an-introduction-to-iptables.aspx</feedburner:origLink></item><item><title>Life outside .NET, or “How to check out your neighbours”</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/Jt8IvVHLVhU/life-outside-net-or-how-to-check-out-your-neighbours.aspx</link><pubDate>Wed, 03 Feb 2010 02:34:19 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:618073</guid><dc:creator>Kyle Baley</dc:creator><slash:comments>22</slash:comments><description>&lt;p&gt;The hillbilly be all Java’d up these days. For coming on three weeks, I’ve been the lone developer on a project based on &lt;a href="http://code.google.com/webtoolkit/"&gt;Google Web Toolkit&lt;/a&gt;. It’s a web framework (naturally) that allows developers to build applications in Java and compiles it down to JavaScript, CSS, and HTML. Scoff all you want, if it were any other company behind it, I’d probably be right there with you.&lt;/p&gt;  &lt;p&gt;We considered quite a few technologies before landing on this one. We went through Ruby, &lt;a href="http://sharparchitecture.net"&gt;Sharp Architecture&lt;/a&gt;, &lt;a href="http://openrasta.com"&gt;Open Rasta&lt;/a&gt;, Moo Tools, and probably several others. I can defend ending up Google Web Toolkit privately if you want but putting the thought process up in a public forum is going to lead to comments that I’m too tired to moderate these days. And yes, I’ve heard of &lt;a href="http://projects.nikhilk.net/ScriptSharp/ReleaseHistory"&gt;Script #&lt;/a&gt;, too.&lt;/p&gt;  &lt;p&gt;Coming at this from a .NET developer’s standpoint has been interesting. It’s surprising how much we take for granted in our IDE, for example. I’m still meandering my way through the keyboard shortcuts in Eclipse (after a brief fling with IntelliJ IDEA). One thing I’d really like is a keyboard shortcut for the GWT Compile button, which currently is available only via a toolbar button or a context menu, as far as I can tell. Was happy to find a &lt;a href="http://www.viplugin.com/viplugin/"&gt;VIM plugin&lt;/a&gt; for it too that works as advertised.&lt;/p&gt;  &lt;p&gt;Not sure if this applies to Java in general but within the confines of the Google Web Toolkit, the ecosystem is freakin’ phenomenal. The &lt;a href="http://code.google.com/webtoolkit/overview.html"&gt;documentation page&lt;/a&gt; alone encourages unit testing and the use of an MVP architecture. Once you start reading about it, you can’t help but stumble on a number of other projects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.google.com/p/gwt-presenter/"&gt;gwt-presenter&lt;/a&gt;: A passive view implementation for GWT&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.google.com/p/gwt-dispatch/"&gt;gwt-dispatch&lt;/a&gt;: A command pattern implementation for GWT&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.google.com/p/google-guice/"&gt;Guice&lt;/a&gt;: Google’s dependency injection framework&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.google.com/p/google-gin/"&gt;Gin&lt;/a&gt;: A dependency injection framework for the client part of GWT&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The shocking thing from a .NET perspective is that these concepts are just sort of &lt;em&gt;assumed.&lt;/em&gt; There’s little debate on whether dependency injection is necessary or whether passive view is overkill. Someone watched a presentation from Google IO last year, whipped up a command pattern project based on it, and lo! the people said it was good. Between support for Hibernate and the App Engine data store, I think people would look at you bug-eyed if you even suggested writing your own data access layer.&lt;/p&gt;  &lt;p&gt;The downside to all this as that the tooling seems to be several steps behind what I’m used to in the Microsoft world. It’s still too early to make a fair comparison but even after digging a little deeper into Eclipse, I can’t imagine being quite as productive as I currently am in Visual Studio. Yes, there’s also IntelliJ but our anecdotal evidence suggests that neither Java IDE is seen as a de facto standard. For the moment, I’m sticking with Eclipse simply because all the documentation refers to it and the GWT and App Engine plug-ins for it work out of the box.&lt;/p&gt;  &lt;p&gt;Couple of final shout-outs to two blogs that have been invaluable during the learning curve phase. First is &lt;a href="http://blog.hivedevelopment.co.uk/"&gt;Hive Development&lt;/a&gt; (currently featuring two posts on how to unit test MVP applications in GWT). Second is &lt;a href="http://turbomanage.wordpress.com/"&gt;TurboManage&lt;/a&gt;, whose &lt;a href="http://turbomanage.wordpress.com/2009/10/07/calling-appengine-securely-from-gwt-with-gwt-dispatch/"&gt;sample code&lt;/a&gt; is more detailed than many apps I’ve written.&lt;/p&gt;  &lt;p&gt;Anyway, it’s been an interesting couple of weeks.&lt;/p&gt;  &lt;p&gt;Kyle the Decaffeinated&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=618073" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/Jt8IvVHLVhU" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/kyle.baley/archive/tags/Java/default.aspx">Java</category><category domain="http://codebetter.com/blogs/kyle.baley/archive/tags/GWT/default.aspx">GWT</category><feedburner:origLink>http://codebetter.com/blogs/kyle.baley/archive/2010/02/02/life-outside-net-or-how-to-check-out-your-neighbours.aspx</feedburner:origLink></item><item><title>FubuMVC Learns to Speak Spark</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/bCG2UB1rGao/fubumvc-learns-to-speak-spark.aspx</link><pubDate>Tue, 02 Feb 2010 17:59:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:617884</guid><dc:creator>Jeremy D. Miller</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;From Robert the Grey, &lt;a href="http://blog.cozwecan.com/2010/02/spark-learns-to-speak-fubu.html"&gt;FubuMVC learns to speak Spark&lt;/a&gt;.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;I&amp;#39;ve done the nearly solo OSS thing a couple times to mixed results.&amp;nbsp; I&amp;#39;m painfully aware that good OSS projects have a deeper community of contributors than just one guy, and that&amp;#39;s why I&amp;#39;m so thrilled to see this addition come into the nascent FubuMVC reboot from outside the Dovetail office.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=617884" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/bCG2UB1rGao" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/jeremy.miller/archive/tags/FubuMVC/default.aspx">FubuMVC</category><feedburner:origLink>http://codebetter.com/blogs/jeremy.miller/archive/2010/02/02/fubumvc-learns-to-speak-spark.aspx</feedburner:origLink></item><item><title>A Kick in the Monads – Writer Edition</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/xliWJKApvSk/a-kick-in-the-monads-writer-edition.aspx</link><pubDate>Tue, 02 Feb 2010 04:59:02 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:617824</guid><dc:creator>Matthew.Podwysocki</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;In the past couple of Monads posts, we’ve talked briefly about the &lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2009/12/30/much-ado-about-monads-state-edition.aspx"&gt;State&lt;/a&gt; and &lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2010/01/07/much-ado-about-monads-reader-edition.aspx"&gt;Reader&lt;/a&gt; Monads and their potential uses and misuses.&amp;#160; Before this series completes, I have a few more to cover including the Writer, Continuation and eventually Observable monad.&amp;#160; Today, we’ll get started looking at the &lt;a href="http://www.haskell.org/all_about_monads/html/writermonad.html"&gt;Writer Monad&lt;/a&gt; and what it can do for us.&lt;/p&gt;  &lt;h2&gt;What’s the Motivation?&lt;/h2&gt;  &lt;p&gt;Before we dive deep into what the Writer Monad is, let’s go deeper into the motivation of why we might consider this approach.&amp;#160; Like proper developers should when approaching a new concept, we should ask, “What problem are we trying to solve?&amp;#160; What’s the motivation here?” else we end up with an over-applied solution to our problem.&amp;#160; In this case, let’s take the simple example of logging or tracing in our application.&amp;#160; Typically in logging scenarios, we could have the dreaded singleton logger.&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c8c985b4-7304-489b-8213-30af88f249e7" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; doSomething() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  Logger.Instance.Log(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Beginning doing something&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)
  
  &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Doing something&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  
  Logger.Instance.Log(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;End doing something&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Or perhaps, we could have an injected ILogger instance handed to us via a constructor for the purposes of logging.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:1ad0595d-07b0-4406-bf72-c1de4de50bd7" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; ILogger &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;abstract&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; Log : message : &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; unit

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; DreadedManager(logger : ILogger) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; __.DoSomething() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    logger.Log (&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Start doing something&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)
    
    &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Do something&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    logger.Log(&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;End doing something&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Or even in other scenarios, we might imagine putting in some AOP behavior for the purposes of logging, but that may of course not be fined grained enough what we need.&amp;#160; Instead of doing this, how about generating some output “on the side” in a more functional manner.&amp;#160; What if we could instead write something like the following where I add two numbers (simplistic example I know) and then run the computation?&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:3b233269-035f-4b77-8dbe-ef42e6bfb5fd" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; addNumbers x y &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; writer {
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt; logMsg (sprintf &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Adding %d and %d&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; x y)
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;return&lt;/span&gt;&lt;span style="color:#000000;"&gt; x &lt;/span&gt;&lt;span style="color:#000000;"&gt;+&lt;/span&gt;&lt;span style="color:#000000;"&gt; y };;
  
&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;val&lt;/span&gt;&lt;span style="color:#000000;"&gt; addNumbers : &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;int&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;int&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; Writer&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt; list,&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;int&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;

&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; addNumbers &lt;/span&gt;&lt;span style="color:#800080;"&gt;3&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;4&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;|&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; runWriter;;
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;val&lt;/span&gt;&lt;span style="color:#000000;"&gt; it : &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;int&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;*&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt; list &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#800080;"&gt;7&lt;/span&gt;&lt;span style="color:#000000;"&gt;, [&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Adding 3 and 4&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;])&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What we’re seeing is that in my addNumbers function, I take two integer arguments and then log a message and finally return the computed value.&amp;#160; What’s more interesting is the fact that we’re logging something physically alters the signature of our method to indicate such a thing is happening.&amp;#160; When we compute our function, we not only get the result of 7 that we’re expecting, but also our transaction log as well.&amp;#160; Then we can decide what we want to do with the log, for example persist it somewhere, clean it up, etc.&amp;#160; So, how can we do this exactly?&lt;/p&gt;

&lt;h2&gt;Defining the Writer&lt;/h2&gt;

&lt;p&gt;So, now that we covered the motivations around what it is and why we might use it, let’s look at how we might implement it.&amp;#160; In order to maintain both the transaction log and the return value of our method, we’ll need to create a container to hold these values.&amp;#160; In this case, we have the Writer&amp;lt;’W,’T&amp;gt; where the ‘W is the writer, which in our case above was a simple string list, and the ‘T is the result of our method.&amp;#160; We have a constructing function of our Writer which takes a function with no parameters and returns a tuple of our result and the log.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:22d36add-7e58-4aa3-b4dc-19561803b006" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; Writer&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;W,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Writer of (unit &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T * &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;W)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In addition, we’ll need a way to run our Writer so that we can return our tuple of our value and the log.&amp;#160; Let’s create a function called runWriter which computes our Writer.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:051baa4e-629b-4393-bbcc-efa3e60fafb7" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; runWriter&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;W,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; (Writer w) : (&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T * &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;W) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; w()&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Before we get started on the Monad part, there is another piece we need to understand, and that’s the Monoid.&lt;/p&gt;

&lt;h2&gt;Don’t Avoid the Monoid&lt;/h2&gt;

&lt;p&gt;Before everyone panics as I’ve brought up a work that sounds like Monad, just rest easy.&amp;#160; In fact, it’s much easier to understand than the dreaded M word.&amp;#160; &lt;a href="http://en.wikipedia.org/wiki/Monoid"&gt;A Monoid&lt;/a&gt; is an algebraic data structure with a simple associative binary operation and an identity element.&amp;#160; Just to bring that into real-world speak, we could have a Monoid for natural numbers with an identity element of 0 and the associative binary operator of addition, or in the case of lists, we could have the identity element of an empty list and an associative binary operator of append.&amp;#160; In Haskell, such a thing is implemented through a type class, but since in F#, we don’t have this, let’s instead create a simple interface to encompass the same behavior.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:0f43f29a-a256-4583-8d2a-04d73bda42fa" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; IMonoid&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt; =&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;abstract&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; mempty  : unit &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;abstract&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; mappend : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T * &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In this instance, we have two methods we care about, defining our identity (mempty) and our binary operator (mappend).&amp;#160; For example, we could implement a Monoid for a simple F# list such as the following:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:21e5360b-c426-45da-83b9-6108da7cc1e4" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; ListMonoid&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt;() =&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;interface&lt;/span&gt;&lt;span style="color:#000000;"&gt; IMonoid&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T list&amp;gt; with&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.mempty() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; []
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.mappend(a, b) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; a @ b&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This instance in particular will come in handy when we’re talking about a simple logging solution.&amp;#160; Our mempty simply returns an empty list of our ‘T objects and our mappend appends the first list to the next.&amp;#160; Now, what we need is some sort of registration process for our IMonoid instances so that we could pick one up based upon the incoming type.&amp;#160; We could use something like a &lt;a href="http://commonservicelocator.codeplex.com/"&gt;Common Service Locator&lt;/a&gt; to do this and it could be idea for a testing situation, but for now, lets just hand roll a global associations which maps an instance of our IMonoid to our proper type.&amp;#160; &lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:e6534163-541a-4197-8b4d-fb758be4bb98" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; MonoidAssociations &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt;() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
  
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;static&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; associations &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; Dictionary&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Type, obj&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;()
  
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;static&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; Add&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt;(monoid : IMonoid&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
    associations.Add(typeof&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt;, monoid)&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;static&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; Get&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt;() = &lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;match&lt;/span&gt;&lt;span style="color:#000000;"&gt; associations.TryGetValue(typeof&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt;) with &lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#000000;"&gt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;true&lt;/span&gt;&lt;span style="color:#000000;"&gt;, assoc &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; assoc :&lt;/span&gt;&lt;span style="color:#000000;"&gt;?&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; IMonoid&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#000000;"&gt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;false&lt;/span&gt;&lt;span style="color:#000000;"&gt;, _    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
        failwithf &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;No IMonoid defined for %O&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;|&lt;/span&gt;&lt;span style="color:#000000;"&gt; typeof&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Once we have this defined, we could add instances to this associations class such as a string list implementation:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:aae62d8c-bf47-4c38-9fbe-dfba90673893" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#000000;"&gt;MonoidAssociations.Add(&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; ListMonoid&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;())&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And now we can use the associations class to call instances of our IMonoid for our functions of mempty and mappend.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9b917236-7586-4568-a33d-31c42e28e250" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; mempty&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt; = MonoidAssociations.Get&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;().mempty
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; mappend&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt; a b = MonoidAssociations.Get&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;().mappend(a, b)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;After that little diversion, we’re now able to get back to the point of the post, the Writer itself.&amp;#160; But outside of here, that’s probably the last time you’ll probably use the word Monoid.&amp;#160; But, I’m sure now you could impress your friends with the use of said word.&lt;/p&gt;

&lt;h2&gt;Defining the Builder&lt;/h2&gt;

&lt;p&gt;As you may remember from the previous post, the monad must support three basic rules.&amp;#160; First, a type construction, for each underlying type, we must be able to get the corresponding monadic type.&amp;#160; Second, we must have a function that maps an underlying value to a value in the corresponding monadic type, which is called the return function.&amp;#160; Third, we must have a binding operation where the first argument is a value in a monadic type, its second argument is a function that maps from the underlying type of the first argument to another monadic type, and its result is in that other monadic type.&lt;/p&gt;

&lt;p&gt;Let’s first tackle the return function.&amp;#160; From our &lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2010/01/25/a-kick-in-the-monads-creating-extended-builders-part-iii.aspx"&gt;previous creating a Builder posts&lt;/a&gt;, we should remember that the Return should have the following signature where we take a value of T and then return it’s Monadic type.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:783ce1bb-1ed9-48c0-ba6a-b6d5222d034e" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; Builder() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; Return : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T -&amp;gt; Monad&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Our implementation should take a value of a and construct a Writer with a function with no arguments and return a tuple of our value and an empty Monoid instance.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:16ebf02c-3bab-43d5-900e-6cef122e1c57" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; WriterBuilder() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.Return&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;W,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;(a : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T) : Writer&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;W,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt; = &lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;    Writer(&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; () &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; a, mempty())&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Next, we need to define the bind operation.&amp;#160; The point of this method is so that we can bind two monadic types together such as two let! or do! statements.&amp;#160; As you might recall, this method takes a Monadic type of ‘T and a function that takes a ‘T and returns a Monadic type of ‘U, and the return type of our bind should be the Monadic type of ‘U.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:2469df51-34f3-4c77-901e-454f41569b86" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; Builder() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; Bind : computation : Monad&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt; *  &lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;                binder : (&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T -&amp;gt; Monad&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;U&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;) &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; Monad&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;U&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Our implementation should look like the following which creates a Writer with a constructed function which takes no parameters and then calls runWriter on our first Writer m which returns a tuple of our result and a log.&amp;#160; We then execute the binder function with our result a which then gives us our second result and a log.&amp;#160; Finally, we return a tuple of our second result with our two logs appended to each other.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9d7578e7-2816-4774-84d4-f71407178e1c" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; WriterBuilder() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.Bind&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;W,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;U&amp;gt;(&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;    computation: Writer&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;W,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;, 
    binder : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T -&amp;gt; Writer&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;W,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;U&amp;gt;)  : Writer&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;W,&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;U&amp;gt; =&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;    Writer(&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; () &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
      &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (res1, log1)  &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; runWriter computation
      &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (res2, log2) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; runWriter (binder res1)
      &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt;  (res2, mappend&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;W&amp;gt; log1 log2))&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You can find the rest of the methods in order to create a fully functioned builder as a &lt;a href="http://gist.github.com/292392"&gt;Gist&lt;/a&gt; on my GitHub.&amp;#160; Now let’s talk about some helper methods.&amp;#160; The first, and most useful method is the tell which adds an entry to our log.&amp;#160; This function takes a log entry and creates a Writer with a function that takes no arguments and returns a tuple of unit (void for some folks) and our log entry.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:be65f890-6901-4131-9386-d10e7feb6010" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; tell logEntry &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; Writer(&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; () &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; (), logEntry)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Next up is the listen function.&amp;#160; This allows us to listen to our log output that is being generated by our writer.&amp;#160; This function takes a Writer and executes it while returning a tuple of our result and a log, as well as a log.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:ae28e64d-7e5f-47ca-a201-af0b89f9244d" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; listen writer &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
  Writer(&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; () &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; (result, log) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; runWriter writer 
                   &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; ((result, log), log))&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The last function we’ll cover is the censor function.&amp;#160; This function returns a new Writer whose result is the same, but the alters the log based upon what is supplied as a parameter&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:65ac1c4e-930e-4a01-b27a-575c845dabeb" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; pass   m &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
  Writer(&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; () &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ((a, f), w) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; runWriter m &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; (a, f w))
  
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; censor censoredValue writer &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
  writer { &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt; result &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; writer
           &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;return&lt;/span&gt;&lt;span style="color:#000000;"&gt; (result, censoredValue)
         } &lt;/span&gt;&lt;span style="color:#000000;"&gt;|&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; pass&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;Doing Something Useful With It&lt;/h2&gt;

&lt;p&gt;Ok, our helpers are now defined, so let’s go back and figure out how we’re going to log messages.&amp;#160; If you remember from above, we have the tell function which does exactly that.&amp;#160; Let’s implement that to take a message and call the tell function with our message wrapped in a list.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f8db7190-52f1-4b23-a020-ec8296ca47a2" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; logMsg (message : &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; tell [message]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we can try it out in such a function which does some file processing for us with some logging along the way.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9e28b4fe-04bb-4052-a5c3-7a196d88f1b9" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; processFiles files &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; writer {
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;try&lt;/span&gt;&lt;span style="color:#000000;"&gt;

    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt; logMsg &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Begin processing files&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; file &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; files &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;
      &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt; logMsg (sprintf &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Processing %s&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; file) 
      processFile file

    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt; logMsg &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;End processing files&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; 

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;with&lt;/span&gt;&lt;span style="color:#000000;"&gt; e &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt; logMsg (sprintf &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;An exception occurred %s&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt; (e.ToString())) }&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;At the end of this method, it should return to us a tuple of unit and our log entries that happened along the way such as this:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:174a0619-e8b0-452a-ab4f-90d1276175a3" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; processFiles files &lt;/span&gt;&lt;span style="color:#000000;"&gt;|&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; runWriter;;
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;val&lt;/span&gt;&lt;span style="color:#000000;"&gt; it : unit &lt;/span&gt;&lt;span style="color:#000000;"&gt;*&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt; list &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  (&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;null&lt;/span&gt;&lt;span style="color:#000000;"&gt;,
   [&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Begin processing files&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Processing C:\Test1.txt&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;;
    &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Processing C:\Test2.txt&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;; &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#800000;"&gt;End processing files&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;])&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This of course is a pretty contrived and simple example, yet pretty interesting nonetheless.&amp;#160; But, in an impure world that we live in with such languages as F#, C#, etc, how practical is it?&amp;#160; That’s another matter altogether and good arguments on both sides.&amp;#160; Using a writer implies some sort of change to your system to allow for logging, whereas in a more impure environment, logging could take place everywhere.&amp;#160; So, when dealing with an impure world already, just go with what you know.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Once again, by looking at Monads, we can discover what abstractions can be accomplished with them, but just as well, &lt;a href="http://www.haskell.org/haskellwiki/What_a_Monad_is_not"&gt;what they are not about&lt;/a&gt;.&amp;#160; Certainly, functional languages don’t need them, but they certainly can be quite useful.&amp;#160; When we find repeated behavior, such as logging, this abstraction can be quite powerful.&amp;#160; Practically though in languages such as F#, they can be useful, but other patterns and abstractions can as well.&amp;#160; Find the right abstraction and use it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=617824" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/xliWJKApvSk" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/Functional+Programming/default.aspx">Functional Programming</category><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/Haskell/default.aspx">Haskell</category><feedburner:origLink>http://codebetter.com/blogs/matthew.podwysocki/archive/2010/02/01/a-kick-in-the-monads-writer-edition.aspx</feedburner:origLink></item><item><title>Exporting dynamically changing configuration values</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/LruDbyM4rpQ/exporting-dynamically-changing-configuration-values.aspx</link><pubDate>Sun, 31 Jan 2010 21:45:49 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:612532</guid><dc:creator>Glenn Block</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;In my last &lt;a href="http://codebetter.com/blogs/glenn.block/archive/2010/01/27/how-do-i-expose-configuration-information-through-mef.aspx"&gt;post&lt;/a&gt; I discussed how to export configuration. A follow up question in the comments was “What if the values change?” Meaning the values that are exported using the approach I illustrated are static. In the real world however values often can change based on some user setting etc. A variant of the approach however allows the values to not be static. Instead of exporting a value, export a Func which returns the value. MEF offers nice support for this through method exports. For example to allow the “recently used file” config item to change over time, we can modify the Exporter to export that value as a method rather than a property.&lt;/p&gt;  &lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; RecentlyUsedTrackerConfiguration
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;{
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IConfigurationProvider _provider;
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [ImportingConstructor]
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; RecentlyUsedTrackerConfiguration(IConfigurationProvider provider)
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  {
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;     _provider = provider;
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;     MaxItems = provider.GetValue&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&amp;gt;(&amp;quot;&lt;span style="color:#8b0000;"&gt;recentlyUsedTracker.maxItems&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  }
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Export(&amp;quot;&lt;span style="color:#8b0000;"&gt;RecentlyUsedTracker.File&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; GetFile() {
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _provider.GetValue&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&amp;gt;(&amp;quot;&lt;span style="color:#8b0000;"&gt;recentlyUsedTracker.maxItems&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  }
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Export(&amp;quot;&lt;span style="color:#8b0000;"&gt;RecentlyUsedTracker.MaxItems&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; MaxItems {&lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;;}
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;}
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Instead of exporting a property, we are now exporting&amp;#160; the GetFile method. Method exports are imported as delegates, thus RecentlyUsedTracker now looks like this.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;[Export]
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; RecentlyUsedTracker {
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Import(&amp;quot;&lt;span style="color:#8b0000;"&gt;RecentlyUsedTracker.File&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; Func&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&amp;gt; File {&lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;;&lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;;}
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Import(&amp;quot;&lt;span style="color:#8b0000;"&gt;RecnetlyUsedTracker.MaxItems&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; MaxItems {&lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;;&lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;;}
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;}
&lt;/pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Notice above we are importing a Func&amp;lt;string&amp;gt; for the File item rather than string. This gives us the hook to dynamically change File each time it is accessed. You could even go further an parameterized File if you wanted to pass in context to determine which File is returned.&lt;/p&gt;

&lt;h1&gt;It’s still easy to test&lt;/h1&gt;

&lt;p&gt;With this approach RecentlyUsedTracker is still easy to test. With lambda syntax it is pretty painless to pass in test values when the class is under test.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=612532" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/LruDbyM4rpQ" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/glenn.block/archive/tags/MEF/default.aspx">MEF</category><feedburner:origLink>http://codebetter.com/blogs/glenn.block/archive/2010/01/31/exporting-dynamically-changing-configuration-values.aspx</feedburner:origLink></item><item><title>From Hyper-V back (?) to Virtual PC</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/pEkE65PWGkg/from-hyper-v-back-to-virtual-pc.aspx</link><pubDate>Sun, 31 Jan 2010 13:56:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:612423</guid><dc:creator>pvanooijen</dc:creator><slash:comments>6</slash:comments><description>&lt;p&gt;For over a year I have been &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2008/09/15/nice-laptop-for-a-developer-running-windows-workstation-2008.aspx"&gt;using Server 2008, 64 bits, as OS for my laptop&lt;/a&gt;. The main reason for this platform was Hyper-V. Almost every other project I&amp;rsquo;ve been working on needs another virtual server.&amp;nbsp; And each location I am working has a different network. With Hyper-V both switching servers and &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2009/11/12/switching-virtual-networks-the-easy-way.aspx"&gt;switching networks&lt;/a&gt; works fast and good. The downside of using Hyper &amp;ndash;V is that it knocks out all possibilities of hibernating or putting my laptop to sleep. &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2009/09/22/windows-workstation-2008-r2-an-even-better-os-for-a-laptop.aspx"&gt;Server 2008 R2 boots a lot faster&lt;/a&gt;, but still. Another downside is that to use Hyper-V you have to run the 64 bit versions, R2 only comes 64 bits. Visual studio is a 32 bit app, runs OK on 64 bits but it is still not the most stable piece of software I know.&lt;/p&gt;
&lt;p&gt;Due to &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2009/12/29/new-year-new-address.aspx"&gt;circumstances&lt;/a&gt; I had to use my laptop more and more in typical mobile situations. Also the way my colleague presses the power button, is back where he was, does his thing, closes the lid and just walks away made me a little jealous. Perhaps I should move on to Windows 7 and try Virtual PC 2009. I had &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2009/05/20/a-first-glimpse-of-virtualization-in-windows-7.aspx"&gt;played with that combination&lt;/a&gt; and it looked promising.&lt;/p&gt;
&lt;p&gt;To see if this was a good idea I set up some some tests &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Is it possible to migrate the hyper-V virtual machines to Windows 7 virtual PC ?&lt;/li&gt;
&lt;li&gt;Can you switch networks in a virtual machine without the need of a reboot ?&lt;/li&gt;
&lt;li&gt;How does a running virtual machine survive a sleeping machine ?&lt;/li&gt;
&lt;li&gt;How does a running virtual machine survive hibernation ?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;All version of hyper-V and virtual PC share the same virtual hard disk (vhd) format. They differ on the integration features, some piece of host specific software installed on the virtual machine to facilitate all communication with virtual machine. Both Hyper-V and Virtual PC have &amp;ldquo;Install integration features&amp;rdquo; as menu option.&lt;/p&gt;
&lt;p&gt;As a test candidate I took a virtual machine with quite a history. It started its life in Virtual PC 200x as a Windows server 2003 machine with several monsters of sql 8 databases, sql reporting services and some COM custom app. Over the years it had been upgraded tot server 2008 and been living under several versions of Virtual server and Hyper &amp;ndash;V. Not something to rebuild from scratch, just getting that version of reporting service to work is a piece of science on itself. In short: a typical real world machine. Under the several host OS-es it had seen several completely different versions of integration services. These were pretty screwed up. Every attempt to install the newest integration services resulted in messages complaining about previous versions. But the machine still worked.&lt;/p&gt;
&lt;h3&gt;Migrating&lt;/h3&gt;
&lt;p&gt;The official recipe to migrate a virtual machine is to uninstall integration services, move the machine and reinstall the integration services of the new host. But you will not find integration services under the installed programs. All attempts to uninstall form the command prompt (/Uninstall) only resulted in the same messages about previous versions.&lt;/p&gt;
&lt;p&gt;What worked is changing the HAL (Hardware Abstraction Layer) of the virtual machine:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Start MSconfig&lt;/li&gt;
&lt;li&gt;Boot Tab&lt;/li&gt;
&lt;li&gt;Advanced Options&lt;/li&gt;
&lt;li&gt;Check the &amp;ldquo;detect HAL&amp;rdquo; box&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After that I just shut down the machine, copied the hard disk and created a new virtual machine in W7 Virtual PC using the copied vhd file as hard disk.&lt;/p&gt;
&lt;p&gt;The machine booted and complained about requiring new drivers. It also required renewed activation. I installed the W7 Virtual PC integration services and allowed the renewed activation (which is never a problem with MSDN OS licenses). And after that the machine just worked fine. All integration was smooth, all software had perfectly survived the migration.&lt;/p&gt;
&lt;h3&gt;Switching networks&lt;/h3&gt;
&lt;p&gt;I can be short on this. This works &lt;a href="http://codebetter.com/blogs/peter.van.ooijen/archive/2009/11/12/switching-virtual-networks-the-easy-way.aspx"&gt;just as smooth as in Hyper-V&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/AA1_5F00_60D48EF4.png"&gt;&lt;img height="492" width="479" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/peter.van.ooijen/AA1_5F00_thumb_5F00_047D90C2.png" alt="AA1" border="0" title="AA1" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Changing the adapter in the settings is instantaneously reflected in the status of the virtual machines adapter. The good thing is that everything works just as well with an adapter with a dynamic IP address as with one with a static address.&lt;/p&gt;
&lt;h3&gt;Sleep and Hibernate&lt;/h3&gt;
&lt;p&gt;The difference between sleep and hibernate is that in sleep mode the RAM of the PC is still powered, so actually the machine is still alive. In hibernate mode all RAM is saved to and restored from disk. &lt;/p&gt;
&lt;p&gt;In Hyper-V the virtual machines are running on the machine level. In virtual PC you start a virtual machine as a logged in user. When logging off the virtual machines are shut down (or hibernated). Instead of logging of I tried both sleep and hibernate with the virtual machine still running. Again all news is good. All functionality completely survives both scenarios. Virtual PC is not ignorant of my actions. When hibernating it will (automatically) disable the integration services. When awakening it restores them.&lt;/p&gt;
&lt;h3&gt;To conclude&lt;/h3&gt;
&lt;p&gt;The only hurdle I had to take was the HAL setting when migrating the machine. All the rest just worked. So I repaved my laptop with Windows 7 and virtual PC 2009. (Just skip the virtual XP step unless you need a virtual XP machine). I was quite satisfied with Server 2008 (except the required full boot) but do like Windows 7 even better. VS worked well and now even works better. But that could be the result of a fresh install (there is no upgrade possible from 2008 to 7).&lt;/p&gt;
&lt;p&gt;And now I can also close the lid of my laptop and leave the building.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=612423" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/pEkE65PWGkg" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/peter.van.ooijen/archive/2010/01/31/from-hyper-v-back-to-virtual-pc.aspx</feedburner:origLink></item><item><title>Dovetail is Hiring</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/nXrsT9H2EjY/dovetail-is-hiring.aspx</link><pubDate>Fri, 29 Jan 2010 21:17:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:611946</guid><dc:creator>Jeremy D. Miller</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;This is a different project than the one we hired for last time.&amp;nbsp; If you&amp;#39;ve spoken to us before, please consider this position separately.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We&amp;#39;re expanding the development team on our line of existing
products. You&amp;#39;ll be working on a small team that develops applications
for large businesses using some of the latest technology. You will be
involved in all aspects of solution development, including analysis,
design, development, testing, documentation, and support.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re
looking for a software developer with demonstrable C# (preferably .NET
2.0 or later) and HTML/CSS experience (ASP.NET MVC is a plus). Any
experience with test-driven development or automated unit testing in
general is a huge plus. Also, participation in the community
(attendance of events, avid blog reader + commenter, or maybe you even
have a blog yourself) will put you firmly in the running for this
position. We&amp;rsquo;re looking for people that believe learning and continuous
improvement are primary responsibilities of a software developer. We&amp;rsquo;re
hiring motivated people for a terrific opportunity with a team of
recognized .NET and agile community leaders.&lt;/p&gt;
&lt;p&gt;Our practices and technologies include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Test-driven development &lt;/li&gt;
&lt;li&gt;Continuous integration &lt;/li&gt;
&lt;li&gt;Behavior-driven design &lt;/li&gt;
&lt;li&gt;Domain-driven design &lt;/li&gt;
&lt;li&gt;HTML, CSS, Javascript (jQuery) &lt;/li&gt;
&lt;li&gt;ASP .NET MVC &lt;/li&gt;
&lt;li&gt;C# 3.0, .NET 3.5, Visual Studio 2008 &lt;/li&gt;
&lt;li&gt;SQL 2008 &lt;/li&gt;
&lt;li&gt;Oracle &lt;/li&gt;
&lt;li&gt;NHibernate 2.x &lt;/li&gt;
&lt;li&gt;StructureMap&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Email us and tell us why you&amp;rsquo;d make a great addition to our team: &lt;a href="mailto:tech-jobs@dovetailsoftware.com"&gt;tech-jobs@dovetailsoftware.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is a full-time, on-site position in our Austin, TX office. Please DO NOT contact us for outsourcing or tele-commuting.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=611946" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/nXrsT9H2EjY" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/jeremy.miller/archive/2010/01/29/dovetail-is-hiring.aspx</feedburner:origLink></item><item><title>Shrink your Views with FubuMVC Html Conventions</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/VsCpOeEcW3A/shrink-your-views-with-fubumvc-html-conventions.aspx</link><pubDate>Fri, 29 Jan 2010 17:00:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:611847</guid><dc:creator>Jeremy D. Miller</dc:creator><slash:comments>8</slash:comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yesterday I was able to &amp;ldquo;push&amp;rdquo; into Github the work I&amp;rsquo;ve been doing for convention based Html generation in FubuMVC.&amp;nbsp; What the hell is &amp;ldquo;convention based Html generation?&amp;rdquo; you ask?&amp;nbsp; It&amp;rsquo;s simple in concept.&amp;nbsp; Your team has policies, formal or informal, for how you build Html elements for the fields in a ViewModel.&amp;nbsp; If your familiar with MvcContrib&amp;rsquo;s &lt;a href="http://www.lostechies.com/blogs/hex/archive/2009/06/09/opinionated-input-builders-for-asp-net-mvc-using-partials-part-i.aspx"&gt;Opinionated Input Builders&lt;/a&gt; or MVC2&amp;rsquo;s Templates feature (very well described by &lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html"&gt;Brad Wilson here&lt;/a&gt;), we&amp;rsquo;re doing the same thing &lt;i&gt;conceptually&lt;/i&gt; but with much different mechanics.&amp;nbsp; Right now, I&amp;rsquo;m focused on the very basic building block methods that appear on FubuMVC view&amp;rsquo;s (remember that we basically force all views in FubuMVC to be strongly typed with a single ViewModel):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;InputFor( expression ) &amp;ndash; write an Html element to edit a single property on the ViewModel.&amp;nbsp; Instead of calling TextboxFor(x =&amp;gt; x.Something) or DropdownListFor(x =&amp;gt; x.Other) we can just say InputFor(x =&amp;gt; x.Some.Property.On.The.ViewModel) and let the conventions figure out what to do from there.&amp;nbsp; If we need to change the model property to something else, or change our conventions about how elements should be constructed, no big deal.&lt;/li&gt;
&lt;li&gt;DisplayFor( expression ) &amp;ndash; write an Html element to display the value of a single property value on the ViewModel.&amp;nbsp; String fields are just displayed.&amp;nbsp; Entity fields may be displayed as a link to more information on that link.&amp;nbsp; Date fields are shown in short date format, etc.&lt;/li&gt;
&lt;li&gt;LabelFor( expression ) &amp;ndash; write an Html &amp;ldquo;label&amp;rdquo; element for the field.&amp;nbsp; Out of the box, FubuMVC will just put in the field name, but that&amp;rsquo;s not all that useful.&amp;nbsp; In our Dovetail project we have this tied into our localization subsystem to pluck out a localized header text for the desired property.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m dubious that the form auto-generation stuff that MVC2 does has much real world value, but it would certainly be possible to build on top of what we already have.&amp;nbsp; In a follow up post I&amp;#39;ll show more of the DSL-ey approach for creating simple forms that uses InputFor/DisplayFor/LabelFor as building blocks.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;&lt;b&gt;Example&lt;/b&gt;&lt;/h4&gt;
&lt;p&gt;In our system we have a small Entity class named Address (all systems of any complexity have an &amp;ldquo;Address&amp;rdquo; class, but they&amp;rsquo;re all different) with a property for the first line of the address called Address1:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color:#2b91af;"&gt;Required&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;MaximumStringLength&lt;/span&gt;(250)]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; Address1 { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Leaving the appropriateness of the approach aside (it&amp;rsquo;s working very well), we use attributes for our simple validation rules (and also use those to generate &amp;ldquo;not null&amp;rdquo; / string length types of rules in our database).&amp;nbsp; On the client side, we use &lt;a href="http://docs.jquery.com/Plugins/Validation"&gt;jQuery Validation&lt;/a&gt; to do input validation in the browser.&amp;nbsp; jQuery Validation is very simple to use (as long as you color within the lines).&amp;nbsp; All I need to do is add classes and some attributes to the &amp;lt;input&amp;gt; and &amp;lt;select&amp;gt; elements to declaratively apply validation rules.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;In usage, we could build the input Html element for a field by just calling InputFor() like this:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;dd&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt; &lt;span style="color:blue;"&gt;this&lt;/span&gt;.InputFor(m =&amp;gt; m.Site.PrimaryAddress.Address1).Id(&lt;span style="color:#a31515;"&gt;&amp;quot;site-address1&amp;quot;&lt;/span&gt;)&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;dd&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In our Dovetail system the above call generates this Html:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;input&lt;/span&gt; &lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;site-address1&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;required&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;text&amp;quot;&lt;/span&gt; &lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;SitePrimaryAddressAddress1&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;label&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Address 1&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;maxlength&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;250&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;value&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Did you see what happened there?&amp;nbsp; When we create an input element for the Address.Address1, the conventions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Built a textbox element.&amp;nbsp; If the property was a boolean, the conventions would build a checkbox instead.&amp;nbsp; Likewise, if the property is a DateTime or DateTime? field the conventions would build a date picker.&lt;/li&gt;
&lt;li&gt;Set a &amp;ldquo;name&amp;rdquo; attribute&amp;rdquo; that matches our naming convention so that model binding works smoothly from client to server and in automated testing scenarios.&amp;nbsp; In our case we just take the &amp;ldquo;path&amp;rdquo; to a property from the ViewModel and tear out the &amp;ldquo;.&amp;rdquo; characters&lt;/li&gt;
&lt;li&gt;Adds the &amp;quot;label&amp;rdquo; attribute with the localized header name for this field.&amp;nbsp; This is used in conjunction with the jQuery validation to present a clean, localized validation summary on the screen&lt;/li&gt;
&lt;li&gt;Recognizes the presence of the [MaximumStringLength] attribute and sets the &amp;ldquo;maxlength&amp;rdquo; attribute&lt;/li&gt;
&lt;li&gt;Puts the property value into the &amp;ldquo;value&amp;rdquo; attribute.&amp;nbsp; The example I used happens to come from a &amp;ldquo;New&amp;rdquo; screen, so the value is blank&lt;/li&gt;
&lt;li&gt;Recognizes the presence of the [Required] attribute and adds the &amp;ldquo;required&amp;rdquo; class to the element&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;By the way, did you see how I overrode the &amp;ldquo;id&amp;rdquo; property of that textbox?&amp;nbsp; I&amp;rsquo;ll talk more about that at the bottom, but that represents a huge advantage that FubuMVC&amp;rsquo;s model has over both MvcContrib and MVC2.&amp;nbsp; &lt;b&gt;You can happily modify or enhance the convention-generated Html input on a case by case basis&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;&lt;b&gt;Can I make my own Conventions?&lt;/b&gt;&lt;/h4&gt;
&lt;p&gt;One of the overarching principles of FubuMVC is to push the usage of Convention over Configuration as far as it can go while still allowing FubuMVC adopters to create and add their own conventions.&amp;nbsp; The Html conventions are no different.&amp;nbsp; When you register / configure conventions for the Html you can register either &amp;ldquo;Builders&amp;rdquo; that know how to generate the HtmlTag (I&amp;rsquo;ll explain HtmlTags later) for a certain class of properties:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;delegate&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;TagBuilder&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;ElementRequest&lt;/span&gt; request);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IElementBuilder&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;TagBuilder&lt;/span&gt; CreateInitial(&lt;span style="color:#2b91af;"&gt;AccessorDef&lt;/span&gt; accessorDef);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;or &amp;ldquo;Modifiers&amp;rdquo; that enrich HtmlTag&amp;rsquo;s:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;delegate&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;TagModifier&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;ElementRequest&lt;/span&gt; request, &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt; tag);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IElementModifier&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;TagModifier&lt;/span&gt; CreateModifier(&lt;span style="color:#2b91af;"&gt;AccessorDef&lt;/span&gt; accessorDef);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;These ElementBuilder&amp;rsquo;s and ElementModifier&amp;rsquo;s can either be classes that you build yourself and &amp;ldquo;plug&amp;rdquo; in, or you can use the Html convention DSL shown below to create common, simple types of policies (think, if this attribute exists, add this class).&amp;nbsp; A custom ElementBuilder might look like this:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// This builder is only for creating the display tag&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// for a date time field on one of our &amp;quot;activity log&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// models&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;LogDateDisplay&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;ElementBuilder&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Does this builder apply to a property?&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;protected&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; matches(&lt;span style="color:#2b91af;"&gt;AccessorDef&lt;/span&gt; def)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; def.ModelType.Closes(&lt;span style="color:blue;"&gt;typeof&lt;/span&gt; (&lt;span style="color:#2b91af;"&gt;LogViewModel&lt;/span&gt;&amp;lt;&amp;gt;)) &amp;amp;&amp;amp; def.Accessor.PropertyType.IsDateTime();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Renders a date in long time format and also sticks the header&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// text into the title attribute&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt; Build(&lt;span style="color:#2b91af;"&gt;ElementRequest&lt;/span&gt; request)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; title = &lt;span style="color:#2b91af;"&gt;LocalizationManager&lt;/span&gt;.GetHeader(request.Accessor.InnerProperty);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;span&amp;quot;&lt;/span&gt;).Text(request.ToDisplay(&lt;span style="color:#a31515;"&gt;&amp;quot;{0:F}&amp;quot;&lt;/span&gt;)).Title(title);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Alrighty, let&amp;rsquo;s move on to registering our conventions.&amp;nbsp; From the top, I create a class to hold my project&amp;rsquo;s Html conventions like so:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// HtmlConventionRegistry is the base class that provides the DSL&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// This is an example of &amp;quot;Object Scoping&amp;quot; from Fowler speak like&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// StructureMap&amp;#39;s Registry and Fluent NHibernate&amp;#39;s ClassMap&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;DovetailHtmlConventions&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;HtmlConventionRegistry&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; DovetailHtmlConventions()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; validationAttributes();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numbers();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Profile(&lt;span style="color:#a31515;"&gt;&amp;quot;edit&amp;quot;&lt;/span&gt;, x =&amp;gt; x.Editors.Builder&amp;lt;&lt;span style="color:#2b91af;"&gt;EditInPlaceBuilder&lt;/span&gt;&amp;gt;());&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; editors();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Labels.Builder&amp;lt;&lt;span style="color:#2b91af;"&gt;LabelBuilder&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Displays.Builder&amp;lt;&lt;span style="color:#2b91af;"&gt;LogDateDisplay&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Displays.Builder&amp;lt;&lt;span style="color:#2b91af;"&gt;DisplayBuilder&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; editors()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.Builder&amp;lt;&lt;span style="color:#2b91af;"&gt;ValueObjectDropdownBuilder&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.IfPropertyIs&amp;lt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt;&amp;gt;().BuildBy(request =&amp;gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;CheckboxTag&lt;/span&gt;(request.Value&amp;lt;&lt;span style="color:blue;"&gt;bool&lt;/span&gt;&amp;gt;()).Style(&lt;span style="color:#a31515;"&gt;&amp;quot;width&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;auto !important&amp;quot;&lt;/span&gt;).Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;value&amp;quot;&lt;/span&gt;, request.ElementId));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.Always.Modify((request, tag) =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;label&amp;quot;&lt;/span&gt;, request.Header());&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;, request.ElementId);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Ugly hack because of the hacky Edit in Place jQuery plugin we use, but&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// I&amp;#39;m gonna kill it some day&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.IfPropertyTypeIs(t =&amp;gt; t.IsDateTime()).Modify(x =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (!x.HasMetaData(&lt;span style="color:#2b91af;"&gt;EditInPlaceBuilder&lt;/span&gt;.EDITABLE_ATTRIBUTE_NAME))&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.AddClass(&lt;span style="color:#a31515;"&gt;&amp;quot;DatePicker&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Setting up rules for tagging elements with jQuery validation&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// metadata&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// I think that a lot of this gets added into the core Fubu as a&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// &amp;quot;jQueryValidationPack&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; numbers()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.IfPropertyIs&amp;lt;&lt;span style="color:#2b91af;"&gt;Int32&lt;/span&gt;&amp;gt;().Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;max&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;Int32&lt;/span&gt;.MaxValue);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.IfPropertyIs&amp;lt;&lt;span style="color:#2b91af;"&gt;Int16&lt;/span&gt;&amp;gt;().Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;max&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;Int16&lt;/span&gt;.MaxValue);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.IfPropertyIs&amp;lt;&lt;span style="color:#2b91af;"&gt;Int64&lt;/span&gt;&amp;gt;().Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;max&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;Int64&lt;/span&gt;.MaxValue);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.IfPropertyTypeIs(t =&amp;gt; t.IsIntegerBased()).AddClass(&lt;span style="color:#a31515;"&gt;&amp;quot;integer&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.IfPropertyTypeIs(t =&amp;gt; t.IsFloatingPoint()).AddClass(&lt;span style="color:#a31515;"&gt;&amp;quot;number&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Declare policies for using validation attributes&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; validationAttributes()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.AddClassForAttribute&amp;lt;&lt;span style="color:#2b91af;"&gt;RequiredAttribute&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;required&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.ModifyForAttribute&amp;lt;&lt;span style="color:#2b91af;"&gt;MaximumStringLengthAttribute&lt;/span&gt;&amp;gt;((tag, att) =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (att.Length &amp;lt; &lt;span style="color:#2b91af;"&gt;Entity&lt;/span&gt;.UnboundedStringLength)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;maxlength&amp;quot;&lt;/span&gt;, att.Length);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.ModifyForAttribute&amp;lt;&lt;span style="color:#2b91af;"&gt;GreaterOrEqualToZeroAttribute&lt;/span&gt;&amp;gt;(tag =&amp;gt; tag.Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;min&amp;quot;&lt;/span&gt;, 0));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Editors.ModifyForAttribute&amp;lt;&lt;span style="color:#2b91af;"&gt;GreaterThanZeroAttribute&lt;/span&gt;&amp;gt;(tag =&amp;gt; tag.Attr(&lt;span style="color:#a31515;"&gt;&amp;quot;min&amp;quot;&lt;/span&gt;, 1));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;&lt;b&gt;HtmlTags&lt;/b&gt;&lt;/h4&gt;
&lt;p&gt;The basis for FubuMVC&amp;rsquo;s Html conventions, and the big differentiating feature from the MVC2 and MvcContrib approach, is the usage of the &amp;ldquo;HtmlTags&amp;rdquo; library as a &lt;a href="http://martinfowler.com/dslwip/SemanticModel.html"&gt;semantic model&lt;/a&gt;.&amp;nbsp; All the Html generation in FubuMVC works by building up HtmlTag objects that represent an Html element graph (HtmlTag&amp;rsquo;s can have children).&amp;nbsp; Think of the old &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.tagbuilder_members.aspx"&gt;TagBuilder class&lt;/a&gt; on steroids.&amp;nbsp; A picture&amp;rsquo;s worth a thousand words, so let&amp;rsquo;s see some samples of HtmlTag in action:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Setting the inner text and adding a class&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt; tag = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;).Text(&lt;span style="color:#a31515;"&gt;&amp;quot;my text&amp;quot;&lt;/span&gt;).AddClass(&lt;span style="color:#a31515;"&gt;&amp;quot;collapsible&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// adding &amp;quot;MetaData&amp;quot; for the jQuery MetaData plugin&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt; tag = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;).Text(&lt;span style="color:#a31515;"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.MetaData(&lt;span style="color:#a31515;"&gt;&amp;quot;a&amp;quot;&lt;/span&gt;, 1);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.MetaData(&lt;span style="color:#a31515;"&gt;&amp;quot;b&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;b-value&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color:#2b91af;"&gt;Test&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; render_multiple_levels_of_nesting_2()&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt; tag = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;html&amp;quot;&lt;/span&gt;).Modify(x =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.Add(&lt;span style="color:#a31515;"&gt;&amp;quot;head&amp;quot;&lt;/span&gt;, head =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; head.Add(&lt;span style="color:#a31515;"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;).Text(&lt;span style="color:#a31515;"&gt;&amp;quot;The title&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; head.Add(&lt;span style="color:#a31515;"&gt;&amp;quot;style&amp;quot;&lt;/span&gt;).Text(&lt;span style="color:#a31515;"&gt;&amp;quot;the style&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.Add(&lt;span style="color:#a31515;"&gt;&amp;quot;body/div&amp;quot;&lt;/span&gt;).Text(&lt;span style="color:#a31515;"&gt;&amp;quot;inner text of div&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.ToCompacted().ShouldEqual(&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;The title&amp;lt;/title&amp;gt;&amp;lt;style&amp;gt;the style&amp;lt;/style&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&amp;lt;div&amp;gt;inner text of div&amp;lt;/div&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The HtmlTag model has been hugely advantageous because:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It greatly simplifies Html construction.&amp;nbsp; No ugly string bashing, class and attribute merging is handled internally by HtmlTag itself, and we&amp;rsquo;ve got plenty of convenience shortcuts.&amp;nbsp; Compare this model to using user controls with tag soup or brute force string manipulation&lt;/li&gt;
&lt;li&gt;Allows us to create an incremental model of &amp;ldquo;policies&amp;rdquo; to add classes and attributes to elements rather than having to make one big blob of code to create the Html (something that plagues both the MvcContrib and MVC2 designs)&lt;/li&gt;
&lt;li&gt;The InputFor(), DisplayFor(), and LabelFor() methods all return the HtmlTag object created by the convention, and HtmlTag itself has fluent builders so that you can override or extend the Html created by the conventions on a case by case basis.&amp;nbsp; We&amp;rsquo;ve gotten some great feedback and help with this feature from the MvcContrib guys, and this is their main complaint with using User Controls.&lt;/li&gt;
&lt;li&gt;The conventional Html generation is pretty testable in basic xUnit tests without ever having to mess with WatiN or Selenium.&amp;nbsp; That&amp;rsquo;s a huge plus in my book&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;HtmlTags is a separate library within FubuMVC that can be used independently (I use it in StoryTeller now). &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;&lt;b&gt;Select Box Example&lt;/b&gt;&lt;/h4&gt;
&lt;p&gt;I&amp;rsquo;ve had this feature, and even the technical direction, in mind since last summer.&amp;nbsp; I finally got to build it out for Dovetail usage because we needed to change the way we do configurable lists in our system.&amp;nbsp; We keep list data in a database table where it&amp;rsquo;s easily editable and extensible (even to the point of adding cascading relationships after the fact for customizations).&amp;nbsp; We need to validate certain fields against that list data, so we mark those fields like this:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// There is no logic associated with Origin&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// other than externalized rules, so having it&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// be a string does no harm&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color:#2b91af;"&gt;Required&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;ValueOf&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;ListNames&lt;/span&gt;.Origin)]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; Origin { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Anytime a property is decorated with the [ValueOf] attribute we know that we need to build a dropdown list to edit that field.&amp;nbsp; All the information that we absolutely need to know to construct that dropdown is available on the property itself, so it made perfect sense to move to convention based Html construction instead of all the repetitive &amp;ldquo;put list data on ViewModel in Controller, transmit to View, fill options in View code&amp;rdquo; work we were doing before.&amp;nbsp; We cache the list data in a static class called ValueObjectRegistry that can give us list data.&amp;nbsp; Using ValueObjectRegistry and the Html Conventions gave us this:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Builds a &amp;lt;select&amp;gt; tag and fills in the list values &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// for any property in our system that is &amp;quot;marked&amp;quot; as being&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// a list field&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ValueObjectDropdownBuilder&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;ElementBuilder&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;protected&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:blue;"&gt;bool&lt;/span&gt; matches(&lt;span style="color:#2b91af;"&gt;AccessorDef&lt;/span&gt; def)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; def.Accessor.HasAttribute&amp;lt;&lt;span style="color:#2b91af;"&gt;ValueOfAttribute&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt; Build(&lt;span style="color:#2b91af;"&gt;ElementRequest&lt;/span&gt; request)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; defaultValue = request.Value&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (defaultValue.IsEmpty())&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; request.ForListName(name =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;ValueObject&lt;/span&gt; @default = &lt;span style="color:#2b91af;"&gt;ValueObjectRegistry&lt;/span&gt;.FindDefault(name);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (@default != &lt;span style="color:blue;"&gt;null&lt;/span&gt;) defaultValue = @default.Key;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SelectTag&lt;/span&gt;(tag =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; request.EachValueObject(vo =&amp;gt; tag.Option(vo.LocalizedText(), vo.Key));&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.SelectByValue(defaultValue);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTag&lt;/span&gt; Build(&lt;span style="color:blue;"&gt;string&lt;/span&gt; listName)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SelectTag&lt;/span&gt;(tag =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:#2b91af;"&gt;ValueObjectRegistry&lt;/span&gt;.GetAllActive(listName).Each(x =&amp;gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.Option(x.LocalizedText(), x.Key);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;var&lt;/span&gt; defaultVO = &lt;span style="color:#2b91af;"&gt;ValueObjectRegistry&lt;/span&gt;.FindDefault(listName);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (defaultVO != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag.SelectByValue(defaultVO.Key);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now that we have ValueObjectDropdownBuilder hooked into our Html conventions, all I need to do on the view is just say:&amp;nbsp; &amp;ldquo;InputFor(x =&amp;gt; x.Case.Origin)&amp;rdquo; and let the conventions handle everything.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Any questions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=611847" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/VsCpOeEcW3A" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/jeremy.miller/archive/tags/FubuMVC/default.aspx">FubuMVC</category><feedburner:origLink>http://codebetter.com/blogs/jeremy.miller/archive/2010/01/29/shrink-your-views-with-fubumvc-html-conventions.aspx</feedburner:origLink></item><item><title>Open Rasta presentation, or “How to throw a rest into the mix”</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/MhU-agBjWts/open-rasta-presentation-or-how-to-throw-a-rest-into-the-mix.aspx</link><pubDate>Thu, 28 Jan 2010 16:56:08 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:611476</guid><dc:creator>Kyle Baley</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;I’m imagining the thought process of some of the session voters for the upcoming &lt;a href="http://live.visitmix.com/"&gt;Mix conference&lt;/a&gt;. “Hey, here’s one on &lt;a href="http://trac.caffeine-it.com/openrasta"&gt;Open Rasta&lt;/a&gt; by the Coding Hillbilly. You know what would be funny? Let’s all vote for it even though he just submitted it on a lark to get some practice after taking time out from speaking engagements. It’ll be fun watching him explain to Mrs. Billy that he *has* to go to Vegas four weeks before he’s heading to Philadelphia for &lt;a href="http://www.udidahan.com/training/"&gt;Udi Dahan’s course&lt;/a&gt;.”&lt;/p&gt;  &lt;p&gt;Yeah, you’re all a bunch o’ comedians, ain’t ya. Well, I’ll show you. You’ll go to my Open Rasta session ready to watch me squirm and you’ll see no such thing. I don’t want to overhype it or anything but I can tell you without a doubt that this session is going to restore your virginity and then take it from you again. Savagely (but tastefully; last thing I need is a bunch of people accusing me of statutory rape in the middle of a presentation). Then maybe next time you’ll think twice before crossing a coder of the earth, woncha!&lt;/p&gt;  &lt;p&gt;Couple of interesting tidbits on the session:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Somewhere along the line, the original title got changed. I submitted it with: “Open Rasta: The REST framework MVC wants to be.” &lt;/li&gt;    &lt;li&gt;I also submitted a session on &lt;a href="http://www.sharparchitecture.net"&gt;S#arp Architecture&lt;/a&gt;. (What can I say? I’m a web framework kinda guy.) I found it interesting that the Open Rasta one got chosen and the #arch one didn’t. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So while you’re waiting for Mix, have a gander at Open Rasta to see what all &lt;a href="http://codebetter.com/blogs/kyle.baley/archive/2009/04/19/openrasta-or-how-to-speak-rest.aspx"&gt;the hubbub&lt;/a&gt; is about. Between this and my new contract using Google Web Toolkit, that should set the stage for my post activity for the next few months.&lt;/p&gt;  &lt;p&gt;Kyle the Bastardized&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=611476" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/MhU-agBjWts" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/kyle.baley/archive/tags/Presenting/default.aspx">Presenting</category><category domain="http://codebetter.com/blogs/kyle.baley/archive/tags/REST/default.aspx">REST</category><category domain="http://codebetter.com/blogs/kyle.baley/archive/tags/Open+Rasta/default.aspx">Open Rasta</category><feedburner:origLink>http://codebetter.com/blogs/kyle.baley/archive/2010/01/28/open-rasta-presentation-or-how-to-throw-a-rest-into-the-mix.aspx</feedburner:origLink></item><item><title>Beyond web.config</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/XAQpdqZ68B0/beyond-web-config.aspx</link><pubDate>Thu, 28 Jan 2010 14:43:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:611421</guid><dc:creator>karl</dc:creator><slash:comments>23</slash:comments><description>&lt;p&gt;I recently needed a configuration mechanism which would detect changes without requiring an application domain restart. I also wanted to move away from XML. This is what I came up with (and hopefully I&amp;#39;ll get some helpful feedback).&lt;/p&gt;
&lt;p&gt;First, we declare a ConfigurationData object which holds our actual configuration values:&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;public interface IConfigurationData
{
   bool LogAll{ get; }
   string CdnUrl{ get; }
}

public class ConfigurationData : IConfigurationData
{
   private bool _logAll;
   private int _cdnUrl;
   
   public bool LogAll
   {
      get { return _logAll; }
      set{ _logAll = value; }
   }
   public string CdnUrl
   {
      get { return _cdnUrl; }
      set { _cdnUrl = value; }
   }
}&lt;/pre&gt;
&lt;p&gt;There isn&amp;#39;t much to explain here, so let&amp;#39;s move on to the class that does the heavy lifting:&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;public static class Configuration
{
   private static readonly string _applicationPath = HttpRuntime.AppDomainAppPath;
   private static ConfigurationData _instance = LoadInitialConfiguration();

   public static IConfigurationData GetInstance
   {
      get { return _instance; }
   }

   private static ConfigurationData LoadInitialConfiguration()
   {
      var watcher = new FileSystemWatcher(_applicationPath, &amp;quot;settings.config&amp;quot;);
      watcher.NotifyFilter = NotifyFilters.LastWrite;
      watcher.Changed += (s, e) =&amp;gt; _instance = LoadConfiguration();
      watcher.EnableRaisingEvents = true;
      return LoadConfiguration();
   }
   private static ConfigurationData LoadConfiguration()
   {
      return Converter.DeserializeFromFile&amp;lt;ConfigurationData&amp;gt;(_applicationPath + &amp;quot;settings.config&amp;quot;, &amp;quot;_&amp;quot;);
   }        
}&lt;/pre&gt;
&lt;p&gt;The class essentially loads the &lt;code&gt;~settings.config&lt;/code&gt; file, and sets up a watch to reload it whenever it changes. Here I&amp;#39;m using JSON (and my &lt;a href="http://codeplex.com/jsoncf"&gt;own JSON library&lt;/a&gt;) to read the file, but you could use anything, such as yaml or xml. The file might look something like:&lt;/p&gt;
&lt;pre&gt;{
   &amp;quot;logAll&amp;quot;: true,
   &amp;quot;_cdnUrl&amp;quot;: &amp;quot;http://cdn.mysite.com/&amp;quot;
}&lt;/pre&gt;
&lt;p&gt;If you are using a DI framework, such as ninject, you can hook it via:&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;Bind&amp;lt;IConfigurationData&amp;gt;().ToMethod(c =&amp;gt; Configuration.GetInstance);&lt;/pre&gt;
&lt;p&gt;otherwise, you can call it directly from code with:&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;if (Configuration.GetInstance.LogAll) {...}&lt;/pre&gt;
&lt;p&gt;There are two things you&amp;#39;ll need to be careful with. First you&amp;#39;ll want to make sure to avoid caching values within a class. For example, if you did something like:&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;public static class HtmlExtensions
{
   private static readonly string _cdnUrl = Configuration.GetInstance.CdnUrl;
}&lt;/pre&gt;
&lt;p&gt;then a copy of &lt;code&gt;CdnUrl&lt;/code&gt; would be stored in _cdnUrl and changes to your &lt;code&gt;&lt;/code&gt; file wouldn&amp;#39;t be available to this class.&lt;/p&gt;
&lt;p&gt;Secondly, the &lt;code&gt;Changed&lt;/code&gt; event is known to fire twice. This shouldn&amp;#39;t cause any threading issues, but if your LoadConfiguration is particularly intensive, or if you happen to be debugging something, then you&amp;#39;ll at least know to expect it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=611421" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/XAQpdqZ68B0" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/karlseguin/archive/2010/01/28/beyond-web-config.aspx</feedburner:origLink></item><item><title>NDepend v3 is now 100% integrated in Visual Studio.</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/FnLEmvpVmkY/ndepend-v3-is-now-100-integrated-in-visual-studio.aspx</link><pubDate>Thu, 28 Jan 2010 09:21:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:611387</guid><dc:creator>Patrick Smacchia</dc:creator><slash:comments>18</slash:comments><description>&lt;p&gt;First of all, if you are like me, you certainly don&amp;rsquo;t want another
Visual Studio extension that will slow down your work environment. So
let&amp;rsquo;s be clear: tremendous efforts have been put on performance and
memory consumption. &lt;b&gt;Even on large code base, made of hundreds of
thousands of lines of code and dozens of VS projects, Visual Studio is
not noticeably slow down by the NDepend v3 addin.&lt;/b&gt; Check by yourself and try NDepend v3.0.0 Beta3 &lt;a target="_blank" href="http://www.ndepend.com/Version3BetaProgram.aspx"&gt;&lt;b&gt;here &lt;/b&gt;&lt;/a&gt;(v3 Beta3 pro works with v2 pro licenses and a v3 trial version is also available). &lt;b&gt;VisualStudio 2010, 2008 and 2005&lt;/b&gt;
are supported. VS 2010 Beta2 is not supported, NDepend v3 Beta3 works
on the limited VS 2010 SLCTP3 and hopefully it will work with VS 2010
RC1 (to be released in a few weeks in February).&lt;br /&gt;&lt;br /&gt;So what does NDepend v3 brings to the table? &lt;b&gt;Simply
put, what NDepend v2 does in the Continuous Integration/Build process,
NDepend v3 does it live at development-time inside Visual Studio&lt;/b&gt;
(of course CI/Build integration facilities are still supported). A
progress circle, in the status bar of Visual Studio, constantly informs
the developer if the code currently violates some CQL rules. An
informative window appear when the circle is hovered by the mouse.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/ProgressCircleTooltip.png"&gt;&lt;img src="http://codebetter.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/ProgressCircleTooltip.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If
you are serious about conventions in your code base, you can easily
define your own CQL rules and make sure that they are checked
automatically and often, even before developers commit their changes.
CQL rules cover a wide range of concerns, including: &lt;i&gt;structuring&amp;nbsp; ;&amp;nbsp; layering&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;components boundaries &lt;/i&gt;&lt;i&gt;;&amp;nbsp; &lt;/i&gt;&lt;i&gt;code changes&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;dozens of quality metrics&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;code element naming&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;NET Fx usage&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;API usage&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;API evolution&lt;/i&gt;&lt;i&gt; and ascendant compatibility ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;coverage ratio by tests&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;dead-code detection&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;un-optimal encapsulation,&lt;/i&gt;&lt;i&gt;&amp;nbsp; ;&amp;nbsp; &lt;/i&gt;&lt;i&gt;side-effects and mutability &lt;/i&gt;etc &amp;hellip;(all this is detailed &lt;a target="_blank" href="http://codebetter.com/blogs/patricksmacchia/archive/2008/05/11/write-active-conventions-on-your-code-base.aspx"&gt;&lt;b&gt;here&lt;/b&gt;&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;It
takes 2 to 5 seconds to check hundreds of CQL rules asynchronously on a
low-priority thread in VS, at each compilation, or if your prefer every
N hours (this is easily configurable). The magic behind this
performance achievement comes from what we call &lt;b&gt;incremental analysis&lt;/b&gt;: NDepend v3 only focuses on code that has been changed since the last analysis.&lt;br /&gt;&lt;br /&gt;There are many other innovative capabilities brought by this new version of NDepend, let&amp;rsquo;s briefly mention some of them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Multi VS solutions wide-analysis and collaboration&lt;/b&gt;: A NDepend project can
spawn dozens of VS projects partitioned in several VS solutions. A same
NDepend project can be attached to several VS solutions that represent
your entire code base (eventually including tests projects). Once there
are several solutions opened in several instance of VS (one for tests,
one for UI code, etc.), NDepend menus lets you jump naturally from one
solution to another; Concretely you can go to the source code
definition of code element B defined in VS solution B from anywhere it
is referenced in VS solution A opened in another instance of VS. A
unique possibility and a huge time saver!&lt;/li&gt;
&lt;br /&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Rich Code Search in VS&lt;/b&gt;: All search capabilities of NDepend
are now integrated in VS. VS itself and many other Addins comes with
their own Search facilities. What makes NDepend search different is &lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;li&gt;NDepend search updates result instantly while refining search
criteria, no matter how big is the code base nor the number of matches
found, &lt;/li&gt;
&lt;li&gt;NDepend search can be done according to plenty of different
criteria (by text(s) in name, by regex(s) , by code metrics, by
changes, by visibility, by purity&amp;hellip;),&lt;/li&gt;
&lt;li&gt;NDepend search by name comes with many unique facilities to make code search more efficient (more on this here &lt;a target="_blank" href="http://codebetter.com/blogs/patricksmacchia/archive/2009/04/06/efficiently-searching-code-elements-by-name.aspx"&gt;Efficiently Searching Code Elements by Name&lt;/a&gt;), &lt;/li&gt;
&lt;li&gt;Searching in diff between 2 versions of the code base is a unique way to code review changes (more on this here &lt;a target="_blank" href="http://codebetter.com/blogs/patricksmacchia/archive/2009/03/29/dramatically-leverage-your-code-reviews.aspx"&gt;Drastically leverage your Code Reviews&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Search scope can spawn several VS solutions, includes tier code
matched by search as well, and constitutes a point of jump across multi
VS solutions opened in several VS instances..&lt;/li&gt;
&lt;/ol&gt;
&lt;p style="padding-left:30px;"&gt;&lt;b&gt;&lt;a target="_blank" href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/SearchBig.png"&gt;&lt;img style="border:0;" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/SearchSmall.jpg" width="600" border="0" height="475" alt="" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Multi CQL Query Edition in VS&lt;/b&gt;: CQL is to a code base what
SQL is to a relational database.&amp;nbsp; Interestingly enough, the &amp;quot;Search in
code&amp;quot; feature described above is just a CQL Query generator. You can
edit several CQL Queries at a time in VS to query the code at whim or
readily define new CQL rules, pretty much the same way you would write
SQL code to query a relational database.&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="padding-left:30px;"&gt;&lt;b&gt;&lt;a target="_blank" href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/CQLBig.png"&gt;&lt;img style="border:0;" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/CQLSmall.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Code visualization in VS:&lt;/b&gt; Dependency Matrix, Dependency
Graph and Metric View (treemap) are all available in VS, and you can
jump to and from source code readily. All these panels come with new
asynchronous and abortable computation facilities that you will likely
never notice, since most of the time the panel layout is computed in a
fraction of second.&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="padding-left:30px;"&gt;&lt;b&gt;&lt;a target="_blank" href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/GraphBig.png"&gt;&lt;img style="border:0;" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/GraphSmall.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Continuous comparison with a base line in VS:&lt;/b&gt; For a long
time, NDepend v2.x lets users explore changes between 2 snapshots of a
code base. With NDepend v3, we harness this feature to continuously
provide in VS the information of what has been refactored or added
since a particular base line. We expect that the base line will often
be the most recently released in production version of the code. If you
cared to save on your HardDrive a copy of the source code base line,
NDepend will let you compare in a click from VS changes made in source
files themselves.&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="padding-left:30px;"&gt;&lt;b&gt;&lt;a target="_blank" href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/CompareBig.png"&gt;&lt;img style="border:0;" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/CompareSmall.jpg" width="600" border="0" height="321" alt="" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Reflector disassembly&amp;rsquo;s comparison&lt;/b&gt;: NDepend can command
Reflector from VS to disassemble in source file (in C#, VB.NET, IL
etc.) any class or any method. With this facility, one click is enough
to disassemble 2 versions of the same code element from 2 versions of
the container assembly. Then, NDepend automatically opens the 2
disassembled code text files built with your favorite text comparison
tool. This is ideal if you want to quickly check from production
assemblies which recent changes might have caused a particular bug.&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="padding-left:30px;"&gt;&lt;a target="_blank" href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/ReflectorBig.png"&gt;&lt;img style="border:0;" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/patricksmacchia.V3Announce/ReflectorSmall.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Deep VS Integration: &lt;/b&gt;Whether it is from Solution Explorer or
Code Editor, all NDepend features are available on right-click as soon
as the context can be recognized as a code element (including
application or referenced assembly, namespace, type, method or field).
All NDepend features (CQL query generation, interaction with code
visualization panels, interaction with Reflector...) are grouped under
a single NDepend menu. If you become addict, any NDepend menu can
optionally be shown at the right-click menu first level.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;NDepend Session state preserved&lt;/b&gt;: Now NDepend&amp;#39;s panels states
(and their undo/redo states as well) are persisted across VisualNDepend
or VisualStudio sessions. When you open VS the day after, everything is
in the same state as it was before you shut down your computer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are dozens of others cool features in the product including
Rich informational contextual tooltip, Global summary of the code base,
supports for .NET v4, Silverlight 3 and Reflector 6, dozens of UI
usability enhancements (including some new facilities in the
visualization with the Dependency Graph) etc &amp;hellip; The vast majority of
these evolutions has been driven from users feedback.&lt;br /&gt;&lt;br /&gt;NDepend v3
is now in beta phase and we will have a final version in February. It
is a Go Live beta, we are confident that the current NDepend v3 beta3
is stable and won&amp;rsquo;t disturb you in your work. All NDepend licenses sold
from now are v3 compatible and questions concerning v2 licenses
upgrading will be answered on-time on the web-site. Now &lt;a target="_blank" href="http://www.ndepend.com/Version3BetaProgram.aspx"&gt;download NDepend v3&lt;/a&gt; and harness your VisualStudio work environment!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=611387" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/FnLEmvpVmkY" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/patricksmacchia/archive/2010/01/28/ndepend-v3-is-now-100-integrated-in-visual-studio.aspx</feedburner:origLink></item><item><title>How do I expose configuration information through MEF?</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/xM4iyXSlTZ0/how-do-i-expose-configuration-information-through-mef.aspx</link><pubDate>Wed, 27 Jan 2010 19:01:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:610347</guid><dc:creator>Glenn Block</dc:creator><slash:comments>9</slash:comments><description>&lt;p&gt;&amp;lt;Goal&amp;gt;Post in 15 mins or less :-)&amp;lt;/Goal&amp;gt;&lt;/p&gt;
&lt;p&gt;This question which recently popped on our &lt;a href="http://mef.codeplex.com/Thread/View.aspx?ThreadId=82114"&gt;forums&lt;/a&gt; is one of the common questions we hear from customers. In this particular case, wcoenen (the person in the forums) had recently used information that he wanted to pull from configuration and pipe to a part. He solved the problem by creating a special configuration provider service which he injected into the part to provide the config. The code for the consumer looked like this:&lt;/p&gt;
&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;[ImportingConstructor]
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; RecentlyUsedTracker(IConfigurationProvider configurationProvider)
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;{   
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.recentlyUsedFile = configurationFile.GetValue&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&amp;gt;(&amp;quot;&lt;span style="color:#8b0000;"&gt;recentlyUsedTracker.File&lt;/span&gt;&amp;quot;);   
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.maxItems = configurationProvider.GetValue&amp;lt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&amp;gt;(&amp;quot;&lt;span style="color:#8b0000;"&gt;recentlyUsedTracker.maxItems&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;}&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;As you can see above RecentlyUsedTracker takes an import of configuration provider. The solution above does work. The biggest issue wcoenen raised is that coupling of the part to the config provider makes testing more difficult. It requires a mock service to be passed in to every test. Another subtlety is that you won&amp;rsquo;t know if the data is actually present until the code executes.&lt;/p&gt;
&lt;h1&gt;An alternative approach, use property exports.&lt;/h1&gt;
&lt;p&gt;A different way to approach this problem is to actually export the individual configuration values. We can still use the generic configuration provider, but we can keep a nice separation of concerns.&amp;nbsp; The part can then import these values like any other import. MEF provides a very powerful facility for doing this called property exports. A property export is a property which is decorated with an export attribute. It is special because it provides a place for you to execute custom logic for retrieving a value and returning it to MEF, i.e. a custom factory. This is a different model than the traditional class-level exports which MEF is responsible for the creation . So using a property export we can easily surface configuration information and we can use any method we choose to get the value including the provider. For example, take a look at the code below.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; RecentlyUsedTrackerConfiguration
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IConfigurationProvider _provider;
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [ImportingConstructor]
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; RecentlyUsedTrackerConfiguration(IConfigurationProvider provider)
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  {
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;     _provider = provider;
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;     File = _provider.GetValue&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&amp;gt;(&amp;quot;&lt;span style="color:#8b0000;"&gt;recentlyUsedTracker.file&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;     MaxItems = provider.GetValue&amp;lt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&amp;gt;(&amp;quot;&lt;span style="color:#8b0000;"&gt;recentlyUsedTracker.maxItems&lt;/span&gt;&amp;quot;);
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  }
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Export(&amp;quot;&lt;span style="color:#8b0000;"&gt;RecentlyUsedTracker.File&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; File {&lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;;}
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Export(&amp;quot;&lt;span style="color:#8b0000;"&gt;RecentlyUsedTracker.MaxItems&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; MaxItems {&lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;;}
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;}
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;RecentlyUsedTrackerConfiguration IS a part as you can see it has an importing constructor which takes a provider. But instead of exporting itself, it exports it&amp;rsquo;s properties which use the provider to get the values. It then assigns a string contract to each export which correlates to the configuration item it is exporting.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note: You can&amp;nbsp; make this more compile safe, by using constants or creating custom export attributes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s take a look at our consumer.&lt;/p&gt;
&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;[Export]
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; RecentlyUsedTracker {
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Import(&amp;quot;&lt;span style="color:#8b0000;"&gt;RecentlyUsedTracker.File&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; File {&lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;;&lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;;}
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt; 
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Import(&amp;quot;&lt;span style="color:#8b0000;"&gt;RecnetlyUsedTracker.MaxItems&lt;/span&gt;&amp;quot;)]
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; MaxItems {&lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;;&lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;;}
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;}
&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;RecentlyUsedTracker imports File and MaxItems. It&amp;rsquo;s nice and clean (aside from the attributes :-) ). We can now easily test RecentlyUsedTracker, as he has no dependency on a provider. All he cares about is that the exports he needs are in the container.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;An additional benefit the above approach introduces.&lt;/h1&gt;
&lt;p&gt;If you read my my or &lt;a href="http://blogs.msdn.com/nblumhardt"&gt;Nick&amp;rsquo;s&lt;/a&gt; blog&amp;rsquo;s, then you&amp;rsquo;ve heard us talk about Stable Composition and Rejection. Parts that don&amp;rsquo;t have there required dependencies are rejected. That means that RecentlyUsedTracker will be rejected unless the config items he needs are present. It&amp;rsquo;s consistent with the way the rest of MEF works it ensures consistency of the system. Of course if you &lt;em&gt;want&lt;/em&gt; to allow the part to be created even though the data is not present, you can always set the AllowDefault property on Import = true.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;What else can use this approach for?&lt;/h1&gt;
&lt;p&gt;Using property exports has a million and one uses. Any time you need to integrate legacy or non-MEF components to MEF, property exports are usually a sure win! For example, let&amp;rsquo;s say you have an existing third-party class which you use in your system which is sealed. You can create that class in a property export and surface it to MEF. It&amp;rsquo;s also a great way to surface singletons that you don&amp;rsquo;t want parts to depend on. What do I mean? Check the code below as an example.&lt;/p&gt;
&lt;pre&gt;&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; ApplicationPart
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;{
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  [Export]
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; Application App {
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;    &lt;span style="color:#0000ff;"&gt;get&lt;/span&gt;{ &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; Application.Current;
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;  }
&lt;/pre&gt;
&lt;pre style="background-color:#ffffff;margin:0em;width:100%;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;font-size:10px;"&gt;}&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Any questions?&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=610347" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/xM4iyXSlTZ0" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/glenn.block/archive/tags/WPF/default.aspx">WPF</category><category domain="http://codebetter.com/blogs/glenn.block/archive/tags/silverlight/default.aspx">silverlight</category><category domain="http://codebetter.com/blogs/glenn.block/archive/tags/MEF/default.aspx">MEF</category><feedburner:origLink>http://codebetter.com/blogs/glenn.block/archive/2010/01/27/how-do-i-expose-configuration-information-through-mef.aspx</feedburner:origLink></item><item><title>Business Primitives (1/2)</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/7mZuZs85AgU/business-primitives-1-2.aspx</link><pubDate>Wed, 27 Jan 2010 12:53:39 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:606083</guid><dc:creator>drusellers</dc:creator><slash:comments>11</slash:comments><description>&lt;p&gt;Understanding the business has been stated time and again as being an important part of the development process. In order for me to better support the business one of the &amp;#39;little&amp;#39; things that I am finding greater and greater love for is the &amp;#39;business primitive&amp;#39;, a very small object, often containing only a single field, that completely encapsulates one small, well defined idea of the business. This is most often a specific type of data, like &amp;#39;Money&amp;#39;. &lt;/p&gt;

&lt;p&gt;This does a couple of things for me right off the bat. One, my methods can now ask for these &amp;#39;business primitives&amp;#39; rather than a language primitive which means there is more meaning in my methods so that they need less documentation and that I am less likely to pass the wrong string into the wrong position on a multi-parameter method. Two, I tend to stop talking in &amp;#39;developer-speak&amp;#39; and start talking in the language of the business. &amp;quot;Ahh, so an Instrument is identified by a CUSIP!&amp;quot;&lt;/p&gt;

&lt;p&gt;This is also a very easy way to start experiencing the benefits of DDD&amp;#39;s &amp;#39;Ubiquitous Language&amp;#39;, as you build up a collection of business primitives your ability to discuss the business problem with the business people in the terms of the business should improve. After all, your business partners don&amp;#39;t think in terms of &amp;#39;strings&amp;#39;, &amp;#39;integers&amp;#39;, or &amp;#39;booleans&amp;#39; rather they think of their business process in terms of &amp;#39;real world things&amp;#39; like &amp;#39;Loans&amp;#39;, and &amp;#39;Investments&amp;#39; and most complex things are built up of smaller objects like &amp;#39;Money&amp;#39;, &amp;#39;InterestRate&amp;#39;, and &amp;#39;CUSIP&amp;#39; your company&amp;#39;s concept of primitives.&lt;/p&gt;

&lt;p&gt;As the use of business primitives grows, your understanding of the business should start to stabilize, and  should gain some sense of consistency with the business. For instance, if you have a &amp;#39;Money&amp;#39; class then you have a perfect location to deal with money rounding issues.&lt;/p&gt;

&lt;p&gt;If you find that this would be hard to start doing, I find that it is easier with primitives that are defined outside of the business itself. For example at the bank there is a concept of a ‘CUSIP.’ This is a industrywide identifier used to identify financial securities. It has a set of rules about how it can be composed. (http://en.wikipedia.org/wiki/CUSIP). You are going to have to conform to these standards anyways you might as well put all the rules in one place.&lt;/p&gt;

&lt;p&gt;If you are familiar with DDD then I also want to be clear that &amp;#39;business primitives&amp;#39; are VALUE TYPES, like a string or an integer, their value is their identity. One instance of CUSIP &amp;#39;CUSIP 912827XN7&amp;#39; is equal to (==) another instance of CUSIP &amp;#39;CUSIP 912827XN7&amp;#39;, which makes sense, their identity is their value. This is distinctly different than the DDD ENTITIES where they are not equal based on the their values, but by their ID, so &amp;#39;Loan&amp;#39; with value $100 would not equal another loan that also has a value of $100.&lt;/p&gt;

&lt;p&gt;In closing, why is &amp;#39;primitive envy&amp;#39; (the overuse of programming language primitives in place of real objects) such a pervasive problem? I think that it has a lot to do with UI control binding. When we are building some of our first programs we need to send a string to the screen so we can see &amp;#39;Hello World&amp;#39;, we don&amp;#39;t build out a &amp;#39;Message&amp;#39; object and then send that to the screen through a ViewModel abstraction. But these behaviors that we build early in our careers can be a deep seated habit that is hard to break out of. Its just too easy to think about the UI and that its going to need a string for the name text box, and then code the &amp;#39;name&amp;#39; as a string in your object. So push back, reclaim so OO love and work with your team to build some real business primitives.&lt;/p&gt;

&lt;p&gt;My next post will show how we can implement this process.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=606083" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/7mZuZs85AgU" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/dru.sellers/archive/tags/Small+Ideas/default.aspx">Small Ideas</category><feedburner:origLink>http://codebetter.com/blogs/dru.sellers/archive/2010/01/27/business-primitives-1-2.aspx</feedburner:origLink></item><item><title>MVC or WebForms: It's more about client side vs server side</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/oNYLRGVXhYY/mvc-or-webforms.aspx</link><pubDate>Wed, 27 Jan 2010 03:34:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:605604</guid><dc:creator>Ian Cooper</dc:creator><slash:comments>17</slash:comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2010/01/24/about-technical-debates-both-in-general-and-regarding-asp-net-web-forms-and-asp-net-mvc-in-particular.aspx"&gt;Scott Guthrie has posted&lt;/a&gt; on the &lt;a href="http://www.google.co.uk/search?q=webforms+vs+mvc&amp;amp;ie=utf-8&amp;amp;oe=utf-8&amp;amp;aq=t&amp;amp;rls=org.mozilla:en-GB:official&amp;amp;client=firefox-a"&gt;growing debate&lt;/a&gt; over &lt;a href="http://codebetter.com/blogs/karlseguin/archive/2010/01/22/the-webforms-rant.aspx"&gt;Webforms vs. MVC&lt;/a&gt;, a debate that seems to be raging everywhere (although there is &lt;a href="http://trac.caffeine-it.com/openrasta"&gt;more that one&lt;/a&gt; &lt;a href="http://www.castleproject.org/monorail/index.html"&gt;MVC framework &lt;/a&gt;&lt;a href="http://fubumvc.com/"&gt;out there&lt;/a&gt; too). I agree with Scott&amp;#39;s point about the nature of technical debates, and the acceptance that there are different schools of thought. However, that does not always imply that all schools are equally good solutions to a given problem. &lt;/p&gt;
&lt;p&gt;The issue has been though I think not solely about the MVC pattern, it is also about the shift from providing rich client behavior server-side or client-side. In this area the renewed interest in &lt;a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29"&gt;AJAX&lt;/a&gt; and the emergence of Javascript libraries like &lt;a href="http://www.prototypejs.org/"&gt;Prototype&lt;/a&gt;, &lt;a href="http://script.aculo.us/"&gt;script.aculo.us&lt;/a&gt; and &lt;a href="http://jquery.com/"&gt;JQuery &lt;/a&gt;have been game changers. And for me those RIA paradigms dovetail better with MVC apps than with Webforms applications. At the same time the growth of &lt;a href="http://en.wikipedia.org/wiki/Representational_State_Transfer"&gt;REST &lt;/a&gt;has meant many have re-engaged with the HTTP protocol and its resource oriented model, have turned attention away from&lt;a href="http://msdn.microsoft.com/en-us/library/ms998548.aspx"&gt; page based approaches&lt;/a&gt; to web development toward resource oriented ones. There is a correspondence here, because as the use of client side scripting grows so does the perspective of the server as a resource provider used by the client.&lt;/p&gt;
&lt;p&gt;It is in many ways this shift of paradigm that MVC supports better and why using MVP approaches with WebForms is not a &amp;#39;seperate but equal&amp;#39; answer to modern web development. Its not simply about better conformance to&lt;a href="http://en.wikipedia.org/wiki/Single_responsibility_principle"&gt; Single Responsibility Principle.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;What our frameworks do for us&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Our average web framework has some pretty basic requirements - handle requests for resources from the server by returning an appropriate response. In our case this is HTML. The simple nature of this model underlies the success of the web.&lt;br /&gt;&lt;br /&gt;To support this model our framework needs to route to an appropriate handler in our code that can read the request. Now we could just interrogate that request to pull out post data or query strings, but writing a lot of that code would get old fast, so it helps if our framework can map between form, params and query string values and part of our object model. That way we can manipulate the variables of the request more easily. Now we have to take an appropriate action in response to the request. Generally this is where most of our code plugs in. We get some data and compose a response, in HTML to return in the response. Now just using Response.Write() to output our HTML becomes hard to maintain, so most of us expect our framework to give us&amp;nbsp; some sort of template so that we can separate the static and dynamic portions of our response.&lt;br /&gt;&lt;br /&gt;The MVC pattern enters the fray here when frameworks separate the responsibilities of template to provide view, model to provide response to action, and co-ordination between the two for a request. Criticism of Webforms as lacking effective separation cf concerns is because the aspx file is both responsible for rendering the HTML used as a response and providing the controller for the request. It thus has two reasons to change, because the template changes or because the co-ordination of handling a request changes. These may be orthogonal concerns and make maintenance harder. Some patterns such as MVP try to alleviate this by enforcing separation of these two responsibilities within the framework. this criticism is valid but not complete issue; the significance of &amp;#39;MVC&amp;#39; frameworks is not solely their better separation of concerns.&lt;br /&gt;&lt;br /&gt;Now for sure the devil is in the details, but that&amp;#39;s pretty much it.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Bare Bones&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;#39;MVC&amp;#39; frameworks such as &lt;a href="http://www.asp.net/%28S%28d35rmemuuono1wvm1gsp2n45%29%29/mvc/"&gt;ASP.NET MVC&lt;/a&gt; or &lt;a href="http://www.castleproject.org/monorail/index.html"&gt;Monorail &lt;/a&gt;ttend to have a bare bones approach to meeting these requirements. The framework takes requests and calls an action to service them, mapping request to action parameters. We then carry out the appropriate task and render html through a view engine. MVC frameworks add little on top of this paradigm. The big win here is that this makes them simple to learn and easy to use, because the surface area of the API is small. The surface area for ASP.NET MVC is smaller than that for Webforms and is easier for new developers to learn. It also works in harmony with http and thus expectations. The principle of least surprise is important to APIs because it makes them easier to discover. Understand the problem and you are likely led in search of the solution.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Rich Internet Applications&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Now ASP.NET MVC etc. allow you to return an HTML response, but HTML has its limitations in that it is static. You need to post a request to the server each time you want some new action to occur. In some cases this &amp;#39;complete form and submit&amp;#39; model works, but we have become used, from smart clients, to a more dynamic model that provides feedback as we make selections. We expect choosing from one dropdown such as country to restrict choices such as US State vs. UK county or Post Code vs. Zip Code.&lt;br /&gt;&lt;br /&gt;Out-of-the-box support in web browsers for dynamic behaviour came in the form of Javascript and manipulation of the &lt;a href="http://en.wikipedia.org/wiki/Document_Object_Model"&gt;DOM&lt;/a&gt;. The browser is the smart client in this approach. The issue here is that Javascript development was a challenge for many developers and consequently many development shops. Why? Because folks found client side behaviour did not just require switching to another language, but also learning the DOM, which was also sometimes uncomfortably close to metal for developers weaned on smart client Forms frameworks like Windows Forms, VB, or PowerBuilder. In addition the browser wars meant that the model for programming against the DOM was not the same from browser to browser, further complicating the code that was needed to implement a rich client in the browser. In truth it was expensive. Finally the debugging experience was poor. We were back to tracing the state of variables in order to isolate and fix problems in the browser. For many MIS departments writing sites with a rich client, heavy on javascript, was out-of-reach in other cost or skills.&lt;br /&gt;&lt;br /&gt;To solve this problem WebForms introduces the concept of server side controls - essentially shifting the rich interaction to the server. The server side control abstracts the html control from the client side. The benefit is that it allows you a development approach familiar to forms based programmers. You set and get control properties and write handlers to react to events. But as the events are raised client-side you need effectively mirror all of the control state from the client side to the server. The problem here is that html does not share this with you on a post. You also need to record the event raised for the server side too, as a post is all you know about from http. This brings in ViewState, which captures all the state which a post is not giving you. But once it is implemented I can provide all that dynamic behaviour on the server, skipping and jumping over issues like knowledge of Javascipt and the DOM, as well as browser compatibility issues.&lt;br /&gt;&lt;br /&gt;Of course we can quickly see that with any complex enough page ViewState will grow. As it is embedded in a page it increases the page weight which can hamper performance In addition because we must do an http post to transfer the state of our application back to the server, and then display the response, events are handled by a page refresh. This has the consequence of making the system slower than one which handles the event locally, giving rise to user complaints of flicker or slow response. In addition if you try to cope by adding some AJAX callbacks from your client&amp;nbsp; the question quickly becomes &amp;#39;who owns this state&amp;#39; as you may have copies of the state both on the client and in ViewData being marshalled back and forth to the server.&lt;/p&gt;
&lt;p&gt;Webforms is also a more complex API than MVC and thus harder for developers to learn. Most of us have been at an interview where we have asked, or been asked the question - what is the Webforms lifecycle? Understanding the stages, where viewdata is available and modifiable is not an insignificant learning challenge.&lt;/p&gt;
&lt;p&gt;Given that, for some time I used to recommend building applications using WebForms server-side control model over building applications with client side behaviour. Why? Because of the cost and difficulty of building rich client behaviour in Javascript with the DOM outweighed the cost of learning Webforms.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What Changed?&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;MVC trades the complexity of server side controls for a simpler programming model, supported by client side controls. The emergence of the new breed of Javascript frameworks like &lt;a href="http://www.prototypejs.org/"&gt;Prototype&lt;/a&gt;, &lt;a href="http://jquery.com/"&gt;JQuery&lt;/a&gt;, and &lt;a href="http://script.aculo.us/"&gt;script.aculo.us&lt;/a&gt;, made it far cheaper to code the client behaviour on the client. The elegance and simplicity of these frameworks, their &lt;a href="http://docs.jquery.com/Browser_Compatibility"&gt;abstraction of browser API differences&lt;/a&gt;, and their &lt;a href="http://plugins.jquery.com/"&gt;rich ecosystem&lt;/a&gt; of control &lt;a href="http://docs.jquery.com/Plugins/Authoring"&gt;providers&lt;/a&gt;, lowered the barrier to entry for client-side development providing solutions to common needs such as&amp;nbsp; &lt;a href="http://stackoverflow.com/questions/159025/jquery-grid-recommendations"&gt;grids &lt;/a&gt;. The availability of &lt;a href="http://designbeep.com/2009/11/21/free-amazing-jquery-plugins-and-tutorials-with-demos/"&gt;many free&lt;/a&gt; controls lowers the cost of common UI widgets&amp;nbsp;&lt;a href="http://stackoverflow.com/questions/159025/jquery-grid-recommendations"&gt;&lt;/a&gt;that have often been the preserve of expensive vendor solutions.&lt;/p&gt;
&lt;p&gt;In addition the debugging experience for Javascript has significantly improved from the old trace and dump model with browser plugins such as &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/1843"&gt;Firebug &lt;/a&gt;and &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/07/19/vs-2008-javascript-debugging.aspx"&gt;Visual Studio&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;With a lower cost it has become commercially viable for more development shops to build rich client applications. Best of breed applications do not suffer from the postback flicker issue because they manipulate state locally on the browser and use AJAX calls to the server. With effective client side development, the user experience is akin to smart clients of yesterday, with none of the distribution problems for central IT departments. This rich experience available for the web lies at the heart of the SaaS revolution.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;The MVC model truly shines with AJAX where the target for an AJAX call is just an action on a controller. The affinity to http&amp;rsquo;s resource based model allows for easy definition of the server side support for rich clients. The advatange of MVC frameworks is the &lt;a href="http://mikehadlow.blogspot.com/2008/10/mvc-framework-and-jquery-ajax-heaven.html"&gt;ease with which they dovetail to client-code using frameworks like JQuery&lt;/a&gt;. Client-side programming is back, using modern Javascript libraries!&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;It is this, IMO, which has shifted the balance in favour of MVC. I do not think it any accident that the ASP.NET team shipped JQuery with ASP.NET MVC. I think it was essential to shipping an ASP.NET MVC application that a modern Javascript client library was included to support rich client behaviour on the browser instead of server side. &lt;br /&gt;&lt;b&gt;&lt;br /&gt;From my cold dead hands&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;The attitude of many developers may be &amp;lsquo;you will pry Weforms &lt;a href="http://www.youtube.com/watch?v=O0B_UZNtEk4"&gt;from my cold dead hands&lt;/a&gt;&amp;rsquo;. The march of progress is threatening to do just that. Much of theresistance is based on prior experiences with the cost of client-side development using Javascript, without understanding that the new frameworks available have significantly lowered the barrier to entry there. In addition, Silverlight opens a second front against Webforms by offering rich client development using XAML. If Javascript does not replace Webforms, then XAML will. Server-side controls had their day. They built careers, companies, and fortunes but they are legacy applications now. Client-side controls have returned with fresh offensives that will see their end. If you are building a new web project today you should be looking at an MVC framework.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;For my part the question of Webforms vs. MVC is already an irrelevance. That is yesterday&amp;rsquo;s fight and victory has been declared despite a few units continuing to fight on. The next war is likely to be between Silverlight and Javascript for ownership of the smart client&amp;hellip;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=605604" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/oNYLRGVXhYY" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/ian_cooper/archive/2010/01/27/mvc-or-webforms.aspx</feedburner:origLink></item><item><title>Don't Use Try/Catch</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/GgS2UsfgAcg/don-t-use-try-catch.aspx</link><pubDate>Mon, 25 Jan 2010 15:02:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:605747</guid><dc:creator>karl</dc:creator><slash:comments>38</slash:comments><description>&lt;p&gt;Exception handling has been talked about a lot over the last decade and a half. However, despite a general consensus on how to properly handle exceptions, a divide on usage continues to exist. Improper exception handling is easy to spot, easy to avoid, and is a simple code (and developer) quality metric. I know absolute rules come off as close minded or exaggerated, but as a &lt;b&gt;general&lt;/b&gt; rule you shouldn&amp;#39;t be using try/catch.&lt;/p&gt;
&lt;p&gt;If an exception happens, you need to know about it. If a truly unexpected exception happens, you&amp;#39;re better off (most of the time) crashing than letting the application continue. This is particularly true in a web application where you&amp;#39;ll only crash 1 thread for 1 user while your site remains accessible. The best way to achieve both is let the exception go unhandled and log the exception in a global exception handler. Too often I see developer writing code which masks errors and make it impossible to build a quality system. Users complain about system instability, and developers are left scratching their heads with no leads on what the problems are.&lt;/p&gt;
&lt;p&gt;What&amp;#39;s even more frustrating is when framework code swallows exceptions. Take a look at this example, written by Microsoft:&lt;/p&gt;
&lt;pre class="c-sharp" name="code"&gt;private void LoadImage()
{
    if (this.image != null)
    {
        this.image.Dispose();              
    }
    

    if (source != null)
    {                
        try
        {                  
            source = Path.Combine(Canvas.ApplicationPath, source);                    
            image = new Bitmap(source);                  

           IImagingFactory factory = ImagingFactory.GetImaging();
           factory.CreateImageFromFile(source, out imagingImage);
        }
        catch{}                                                      
    }
}&lt;/pre&gt;
&lt;p&gt;This is a fundamental piece of code which is part of Microsoft&amp;#39;s UI Framework for .NET Compact Framework. The above code is buried within their framework, but through various key APIs is exposed and used extensively. This is simply horrible code. Why would they swallow any exceptions that come out of this code? The above code means that if you try to load an image &lt;code&gt;&amp;quot;images/critical_warning.png&amp;quot;&lt;/code&gt; which doesn&amp;#39;t exist, the application will continue to work normally. There may be cases where this is the behavior that you want, but those would be edge cases, and they should be decided at the application level, not within the framework.&lt;/p&gt;
&lt;p&gt;The only time you should swallow exceptions (&lt;code&gt;catch{..} or catch(Exception){...}&lt;/code&gt;) is in your global exception handler to avoid truly fundamental issues (and recursive global exception handling). You should catch &lt;b&gt;specific&lt;/b&gt; exception (&lt;code&gt;catch(XmlException){...}&lt;/code&gt;) when an exception isn&amp;#39;t unexpected and you know that you can safely proceed. &lt;/p&gt;
&lt;p&gt;A system that swallows and masks exceptions isn&amp;#39;t a healthy system.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=605747" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/GgS2UsfgAcg" height="1" width="1"/&gt;</description><feedburner:origLink>http://codebetter.com/blogs/karlseguin/archive/2010/01/25/don-t-use-try-catch.aspx</feedburner:origLink></item><item><title>A Kick in the Monads – Creating Extended Builders Part III</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/woTuIbWewG0/a-kick-in-the-monads-creating-extended-builders-part-iii.aspx</link><pubDate>Mon, 25 Jan 2010 06:05:54 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:605586</guid><dc:creator>Matthew.Podwysocki</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;&lt;a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2010/01/21/much-ado-about-monads-creating-extended-builders-part-ii.aspx"&gt;So far in this series&lt;/a&gt;, we’ve covered some of the methods you can implement for custom computation expressions (aka Monads) in F# such as bind and return, as well as exception and resource management.&amp;#160; For the last part in the series, we’ll take a look at looping constructs.&amp;#160; As we know, F# is a pragmatic multi-paradigm language which supports not only functional features, but imperative ones as well, which include mutability, looping constructs and so on.&amp;#160; Just as regular F# supports for and while loops, we have the ability to take advantage of them as well inside of our computation expressions by implementing two methods.&amp;#160; Let’s start with the while loop.&lt;/p&gt;  &lt;h2&gt;Implementing the While Method&lt;/h2&gt;  &lt;p&gt;In order to enable the while loop construct within F#, we need to implement the While method.&amp;#160; This method should have the following signature which takes a guard function which takes no parameters and returns a bool, and a monadic type of unit, and the return is a monadic type of unit.&amp;#160; The reason for the unit return is that in imperative programming we typically perform some side effect inside a looping construct such as a while and for loop.&amp;#160; That’s not to say we can’t return a value, and we’ll talk about that later.&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:8dd8bde2-2b24-45e2-976f-9457a6767a83" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; Builder &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; While : guard : unit &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;*&lt;/span&gt;&lt;span style="color:#000000;"&gt;
                 computation : Monad&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;unit&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;
                 Monad&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;unit&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt; We can write a test to express how this should behave once it has been implemented.&amp;#160; In this instance, we want to loop at least once to ensure the loop works and then check our value that has been incremented.&amp;#160; Just as well, we should also write a test to express behavior where it should not increment if the guard is never satisfied.&amp;#160; But in the mean time, let’s focus on the first scenario.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:60bc1403-76b3-48de-a16c-2729d0173ca9" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#000000;"&gt;[&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Fact&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ``&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;while&lt;/span&gt;&lt;span style="color:#000000;"&gt; should increment count``() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; count &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; ref &lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; r &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; reader {
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;while&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt;count &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;
      incr count }
  
  runReader r ()

  areEqual &lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt;count&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now the question is, how do we implement this?&amp;#160; In the case where our guard function fails, we want to return a monadic type of unit which indicates nothing was done, whereas when it succeeds, we want to bind together our computation and a function which takes no parameters and returns a recursive call to our While loop.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5d35954f-7650-4c85-8140-e5305ab3c605" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; ReaderBuilder() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; 

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.While(guard, computation) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; guard() &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;then&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
      this.Bind(computation, (&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; () &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.While(guard,computation))) 
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;else&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
      this.Return ()&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we have the ability to execute any while loop inside our computation expression.&amp;#160; For the most part, this implementation is rather boilerplate and can apply to any number of monad implementations.&amp;#160; Now, let’s move onto implementing for loops.&lt;/p&gt;

&lt;h2&gt;Implementing the For Method&lt;/h2&gt;

&lt;p&gt;Just as we needed to implement the While method to enable while loops in our custom computation expressions, we will need to implement the For method to enable for loops.&amp;#160; In order to implement this method, it should conform to the following signature which takes a sequence of any type, and a body which takes an item from the sequence and returns a monadic type of unit.&amp;#160; &lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:1cf22c82-8b58-4e82-8d7c-4c1895f66cd6" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; Builder &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; For : sequence : seq&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt; *&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;               body : (&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T -&amp;gt; Monad&amp;lt;unit&amp;gt;) -&amp;gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;               Monad&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;unit&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Let’s take a look at how we might use it through the example of a test.&amp;#160; In this instance, we will simply iterate over a for loop and increment a count and then check its result.&amp;#160; In another test, we should also have an empty collection we try to iterate and check that it does not increment.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:cae77d58-6a89-40df-95dd-ad8efde2ef49" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#000000;"&gt;[&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Fact&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;]
&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; ``&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; should increment count``() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; count &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; ref &lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; r &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; reader {
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; i &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#000000;"&gt; to &lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;
      incr count }
  
  runReader r ()

  areEqual &lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt;count&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now, how might we pull this one off?&amp;#160; In order to do this, we must introduce another method, called Delay.&amp;#160; This method helps us delay any side effects from happening until they are absolutely needed.&amp;#160; Unlike Haskell, F# is an eager functional programming language, so such constructs are necessary.&amp;#160; Let’s look at the signature required for the Delay method below, which takes no parameters and returns a monadic type of T.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9a9a1b24-1abd-4008-9996-e6fa68eb86ba" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; Builder &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; Delay : unit &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; Monad&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Knowing this, we can go ahead an implement both our Delay and For methods.&amp;#160; In the Delay method, we simply bind a monadic wrapped unit with our function, when then in turn will return our Reader&amp;lt;’R,’T&amp;gt;.&amp;#160; Next, we have a For method which takes a sequence and a body to run against each item.&amp;#160; We can reuse the Using method to ensure proper disposal for our IEnumerator&amp;lt;T&amp;gt; and then call While with a function of whether we can move next, and then a delayed function which runs the body function against the current item.&amp;#160; Below is how the implementation should look.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:954fa073-f8e6-449f-8a9a-f51c4c5d5e24" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; ReaderBuilder() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.Delay(f) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    this.Bind(this.Return (), f)

  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; this.For(sequence : seq&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;_&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;, body) &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    this.Using(sequence.GetEnumerator(), 
      (&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; enum &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; 
         this.While(
           (&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; () &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; enum.MoveNext()), 
           this.Delay(&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;fun&lt;/span&gt;&lt;span style="color:#000000;"&gt; () &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; body enum.Current))))&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now that we have the looping constructs defined, let’s look at another way of thinking about looping.&lt;/p&gt;

&lt;h2&gt;Looping and Yield Methods Together&lt;/h2&gt;

&lt;p&gt;In addition to the style we’ve shown in this series with our Bind/Return for our non-collection types, we also have the ability to define a a yield statement which looks and acts much like the C# equivalent.&amp;#160; Commonly, this yield is used in conjunction with some sort of looping construct.&amp;#160; For example, this construct is already available on sequence expressions inside F#.&amp;#160; &lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f86af6c4-47f5-4e8d-a6a3-ecb278109203" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#000000;"&gt;seq { &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; i &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#000000;"&gt; to &lt;/span&gt;&lt;span style="color:#800080;"&gt;10&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;
        &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;yield&lt;/span&gt;&lt;span style="color:#000000;"&gt; i &lt;/span&gt;&lt;span style="color:#000000;"&gt;*&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#800080;"&gt;25&lt;/span&gt;&lt;span style="color:#000000;"&gt; }&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Such constructs make a lot of sense when we’re thinking about interactive and reactive collections, the latter of which we’ll get to later when we’re talking about the Reactive Extensions Observable monad.&amp;#160; In order to enable the Yield behavior, we simply need to implement the Yield method which should look like the following:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:6597fbab-1d65-4db3-bd34-e1db22796add" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; Builder &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; Yield : value : &lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T -&amp;gt; Monad&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The actual implementation of this for our Reader (should we decide to implement it) should look no different than our Return method.&amp;#160; To either call return or yield is simply a matter of style when dealing with collection versus non-collection based computation expressions.&amp;#160; Just as we defined the ReturnFrom method in a previous post to enable the return! keyword, we can also follow the same logic to implement the YieldFrom method which should have the following signature.&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:29adf0c7-e423-471e-80e0-539e951ec4f6" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;type&lt;/span&gt;&lt;span style="color:#000000;"&gt; Builder &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;member&lt;/span&gt;&lt;span style="color:#000000;"&gt; YieldFrom : comp : Monad&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#800000;"&gt;T&amp;gt; -&amp;gt; Monad&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;T&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Together, this enables such behavior as getting all the files from a directory like the following:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:69415fd6-eaa1-4f97-8578-77a22463d870" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;open&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.IO

&lt;/span&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;rec&lt;/span&gt;&lt;span style="color:#000000;"&gt; getFiles dir &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; seq {
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; file &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; Directory.GetFiles dir &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;yield&lt;/span&gt;&lt;span style="color:#000000;"&gt; file
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; subDir &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; Directory.GetDirectories dir &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;yield&lt;/span&gt;&lt;span style="color:#000000;"&gt;!&lt;/span&gt;&lt;span style="color:#000000;"&gt; getFiles subDir }&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Just as well, we could use the yield to show Observable collections such as events:&lt;/p&gt;

&lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c28d79a0-5602-4b11-a3ba-2a9fdf5bcd5f" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;overflow:auto;"&gt;&lt;span style="color:#0000FF;"&gt;let&lt;/span&gt;&lt;span style="color:#000000;"&gt; getMouseMove() &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; obs {
  &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; md &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; form.MouseDown &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;
    &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;for&lt;/span&gt;&lt;span style="color:#000000;"&gt; mm &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; form.MouseMove &lt;/span&gt;&lt;span style="color:#000000;"&gt;|&amp;gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; Observable.until form.MouseUp &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;do&lt;/span&gt;&lt;span style="color:#000000;"&gt;
      &lt;/span&gt;&lt;span style="color:#0000FF;"&gt;yield&lt;/span&gt;&lt;span style="color:#000000;"&gt; mm }&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;It’s a matter of style which one we use, whether we are specifying collection like intent or not.&amp;#160; With that, this should wrap up how to implement a custom computation expression.&amp;#160; Much of this code, outside of Bind/Return TryCatch/TryFinally is boilerplate and can apply to any number of computation expression instances such as the State, Reader, Error, Maybe, and some yet to come such as the mother of all monads, the Continuation Monad, and of course the Observable Monad.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Besides the usual Bind and Return functions that we’ve talked about extensively here, there are quite a few other constructs which allow for rich programming models inside our computation expressions that we just explored.&amp;#160; Whereas LINQ has a rather linear programming model based upon monads, the computation expression includes richer features which include exception handling, control statements, loops, and side effects.&amp;#160; &lt;/p&gt;

&lt;p&gt;Still left in this series, we’ll dive into the root of both the F# Async Workflows and Reactive Extensions for .NET, the Continuation Monad as well as the Observable one as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=605586" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/woTuIbWewG0" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/Functional+Programming/default.aspx">Functional Programming</category><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/Haskell/default.aspx">Haskell</category><category domain="http://codebetter.com/blogs/matthew.podwysocki/archive/tags/Reactive+Framework/default.aspx">Reactive Framework</category><feedburner:origLink>http://codebetter.com/blogs/matthew.podwysocki/archive/2010/01/25/a-kick-in-the-monads-creating-extended-builders-part-iii.aspx</feedburner:origLink></item><item><title>Url Resolution in FubuMVC</title><link>http://feedproxy.google.com/~r/CodeBetter/~3/D62EvlnBcQE/url-resolution-in-fubumvc.aspx</link><pubDate>Mon, 25 Jan 2010 04:34:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:605577</guid><dc:creator>Jeremy D. Miller</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;Continuing the thread from my earlier update on the &amp;ldquo;&lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2009/12/15/an-update-on-the-fubumvc-reboot.aspx"&gt;Fubu Reboot&lt;/a&gt;.&amp;rdquo;&amp;nbsp; In an MVC web application (I think this really could apply to WebForms as well, but not to the same extent) you frequently need to resolve the Url that points to a specific subject.&amp;nbsp; In our application at Dovetail, we have the route pattern:&amp;nbsp; &amp;ldquo;sites/edit/{Id}&amp;rdquo; for the page that edits a &amp;ldquo;Site&amp;rdquo; object.&amp;nbsp; When we place links in the views for a given &amp;ldquo;Site&amp;rdquo; object, we need to replace &amp;ldquo;{Id}&amp;rdquo; in the route with the value of the Site.Id property.&amp;nbsp; In another circumstance, we have the routing pattern &amp;ldquo;query/for/{QueryName}/{QueryParam1}&amp;rdquo; for a controller action that takes in this object as its single argument:&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// The [RouteInput] attributes are *a* way to direct Fubu to &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// make these properties by automatically scanned as part of the &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// route pattern.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// This should only be necessary in exception cases&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// My hope is that conventions take you 90% of the way home&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;QueryForRequest&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color:#2b91af;"&gt;RouteInput&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; QueryName { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color:#2b91af;"&gt;RouteInput&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;)]&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; QueryParam1 { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;At many, many times in our application we need to determine the Url string that points to a particular subject or occasionally to a controller action.&amp;nbsp; At the same time, it would be very, very nice to keep the individual controllers and views ignorant of exactly what those Url patterns happen to be in order to make them easier to change.&amp;nbsp; In FubuMVC, that&amp;rsquo;s all done with the IUrlRegistry interface that is automatically placed into your IoC container:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="border-bottom:black thin solid;border-left:black thin solid;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black thin solid;border-right:black thin solid;"&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// This service is injected into your IoC tool of choice as a singleton&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// to give you access to url&amp;#39;s in a type safe way&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Please note that this implementation in no way, shape, or form&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// locks you into a rigid url structure&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IUrlRegistry&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UrlFor(&lt;span style="color:blue;"&gt;object&lt;/span&gt; model);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UrlFor(&lt;span style="color:blue;"&gt;object&lt;/span&gt; model, &lt;span style="color:blue;"&gt;string&lt;/span&gt; category);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UrlFor&amp;lt;TController&amp;gt;(&lt;span style="color:#2b91af;"&gt;Expression&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Action&lt;/span&gt;&amp;lt;TController&amp;gt;&amp;gt; expression);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UrlForNew&amp;lt;T&amp;gt;();&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UrlForNew(&lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt; entityType);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:green;"&gt;// Not sure these two methods won&amp;#39;t get axed.&amp;nbsp; They could just be extension methods in Dovetail code&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UrlForPropertyUpdate(&lt;span style="color:blue;"&gt;object&lt;/span&gt; model);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UrlForPropertyUpdate(&lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt; type);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UrlFor(&lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt; handlerType, &lt;span style="color:#2b91af;"&gt;MethodInfo&lt;/span&gt; method);&lt;/p&gt;
&lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the FubuMVC model, we&amp;rsquo;re basically assuming that controller actions (&lt;a href="http://www.lostechies.com/blogs/joshuaflanagan/archive/2010/01/18/fubumvc-define-your-actions-your-way.aspx"&gt;Fubu actions don&amp;rsquo;t have to be on special Controller classes&lt;/a&gt;, btw) take in 0 or 1 objects as their single input.&amp;nbsp; Taking another step, if you make the input model types unique per controller action, FubuMVC can actually use that type to &amp;ldquo;know&amp;rdquo; what controller action receives that type.&amp;nbsp; Therefore, when I need the Url string that points to a particular Site object, I just pass in that Site object to the UrlRegistry.For(object) method.&amp;nbsp; In the more complex case of the QueryForRequest object above, I do the exact same thing &amp;ndash; even though QueryForRequest clearly points to a different Route.&amp;nbsp; For controller actions that don&amp;rsquo;t take in any input arguments (think HomeController.Index()), you can still use UrlRegistry.UrlFor&amp;lt;HomeController&amp;gt;(x =&amp;gt; x.Index()).&amp;nbsp; &lt;/p&gt;
&lt;p&gt;For those of you familiar with ASP.Net MVC&amp;rsquo;s model, here&amp;rsquo;s some other facts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The lookup of a Url for a Controller Type / Method combination makes no, let me repeat that, no assumptions about the Url pattern.&amp;nbsp; SomethingController.Method1() does not imply that the Url is &amp;ldquo;something/method1.&amp;rdquo;&amp;nbsp; FubuMVC is literally hashing the exact Route pattern for each Controller action and looks up the exact Url at runtime.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;The call to UrlFor() is completely independent of whether or not the Route in question was registered as part of the main application or as part of an Area/Slice.&amp;nbsp; Unlike MVC2, when you&amp;rsquo;re determining the Url to a certain controller action or input object, you do not have to worry about where&amp;nbsp;&amp;nbsp; I think the MVC team thoroughly screwed up their Area support and I&amp;rsquo;d surely hope they scrap it for something better in MVC3.&amp;nbsp; If you&amp;rsquo;re using the MVC framework today, I&amp;rsquo;d strongly recommend you use the bits in MvcContrib instead of MVC2 for areas.&amp;nbsp;&amp;nbsp; &lt;/li&gt;
&lt;li&gt;No magic strings of any kind.&amp;nbsp; Anywhere.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Lastly,&lt;/h4&gt;
&lt;p&gt;The Url resolution is static typed.&amp;nbsp; That&amp;rsquo;s valuable to help prevent coding mistakes and Intellisense is also nice.&amp;nbsp; Honestly, my favorite part is how much more traceable it makes the code rather than relying on strings.&amp;nbsp; One quick CTRL-B shortcut takes you the the controller action behind the Url.&amp;nbsp; In the case of finding the Url for an object, it&amp;rsquo;s one more bounce with CTRL-ALT-F7 (one of my favorite R# shortcuts).&amp;nbsp; In real usage, we have convenience methods on our view types to get at action urls, as well as consuming the IUrlRegistry in our FormFor() and ActionUrlFor() type HtmlHelpers.&lt;/p&gt;
&lt;p&gt;Now that we mostly rely on IUrlRegistry.For(object), IUrlRegistry is relatively easy to mock in most tests.&amp;nbsp; If your tests have to rely on an Expression in IUrlRegistry.UrlFor&amp;lt;T&amp;gt;(x =&amp;gt; Method()), I&amp;#39;d go for some sort of hand rolled stub.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ok, this may be vague, so please ask question.&amp;nbsp; Also, this stuff isn&amp;rsquo;t locked down, so we can actually change it to suit.&amp;nbsp; And I won&amp;rsquo;t even get all paternalistic on you telling you that &amp;ldquo;UrlFor() doesn&amp;rsquo;t really mean UrlFor()&amp;rdquo; if you don&amp;rsquo;t like the API.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://codebetter.com/aggbug.aspx?PostID=605577" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/CodeBetter/~4/D62EvlnBcQE" height="1" width="1"/&gt;</description><category domain="http://codebetter.com/blogs/jeremy.miller/archive/tags/FubuMVC/default.aspx">FubuMVC</category><feedburner:origLink>http://codebetter.com/blogs/jeremy.miller/archive/2010/01/24/url-resolution-in-fubumvc.aspx</feedburner:origLink></item></channel></rss>
