<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>AboutCode.net - .net</title>
    <link>http://www.aboutcode.net/</link>
    <description>Thoughts on Software by Andrew Davey</description>
    <language>en-us</language>
    <copyright>Andrew Davey</copyright>
    <lastBuildDate>Sun, 11 Oct 2009 12:47:03 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>andrew@equin.co.uk</managingEditor>
    <webMaster>andrew@equin.co.uk</webMaster>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=7b4b0ced-9377-4f42-8366-9470a28955e2</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,7b4b0ced-9377-4f42-8366-9470a28955e2.aspx</pingback:target>
      <dc:creator>Andrew Davey</dc:creator>
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,7b4b0ced-9377-4f42-8366-9470a28955e2.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=7b4b0ced-9377-4f42-8366-9470a28955e2</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Say hello to <strong>ProntoCMS</strong> a new open-source web content management system.
</p>
        <p>
The project is hosted here: <a title="http://code.google.com/p/prontocms/" href="http://code.google.com/p/prontocms/">http://code.google.com/p/prontocms/</a></p>
        <p>
Pronto is built on <a href="http://www.asp.net/mvc">ASP.NET MVC</a> and uses <a href="http://jquery.com/">JQuery</a> and
FCKeditor. It is very light-weight and ideal for small websites.
</p>
        <p>
The code in subversion contains a couple of (very minimal) sample projects. Hopefully
I will get around to writing some documentation soon.
</p>
        <p>
Please take a look at the code and let me know what you think.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=7b4b0ced-9377-4f42-8366-9470a28955e2" />
      </body>
      <title>Announcing ProntoCMS</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,7b4b0ced-9377-4f42-8366-9470a28955e2.aspx</guid>
      <link>http://www.aboutcode.net/2009/10/11/AnnouncingProntoCMS.aspx</link>
      <pubDate>Sun, 11 Oct 2009 12:47:03 GMT</pubDate>
      <description>&lt;p&gt;
Say hello to &lt;strong&gt;ProntoCMS&lt;/strong&gt; a new open-source web content management system.
&lt;/p&gt;
&lt;p&gt;
The project is hosted here: &lt;a title="http://code.google.com/p/prontocms/" href="http://code.google.com/p/prontocms/"&gt;http://code.google.com/p/prontocms/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Pronto is built on &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt; and uses &lt;a href="http://jquery.com/"&gt;JQuery&lt;/a&gt; and
FCKeditor. It is very light-weight and ideal for small websites.
&lt;/p&gt;
&lt;p&gt;
The code in subversion contains a couple of (very minimal) sample projects. Hopefully
I will get around to writing some documentation soon.
&lt;/p&gt;
&lt;p&gt;
Please take a look at the code and let me know what you think.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=7b4b0ced-9377-4f42-8366-9470a28955e2" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,7b4b0ced-9377-4f42-8366-9470a28955e2.aspx</comments>
      <category>.net</category>
      <category>cms</category>
      <category>prontocms</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=cceb7b0e-34ad-4d6c-8435-5d7f51fa8771</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,cceb7b0e-34ad-4d6c-8435-5d7f51fa8771.aspx</pingback:target>
      <dc:creator>Andrew Davey</dc:creator>
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,cceb7b0e-34ad-4d6c-8435-5d7f51fa8771.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=cceb7b0e-34ad-4d6c-8435-5d7f51fa8771</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Thanks to everyone who left encouraging comments on my <a href="http://www.aboutcode.net/2009/10/08/ShouldIOpenSourceMyNewCMS.aspx">previous
post about a new CMS</a> I’ve created.
</p>
        <p>
I have decided that I will be open sourcing the project. However I now need a snappy
name for it. Naming is so hard for some reason!
</p>
        <p>
Any ideas are greatly appreciated. The CMS is light-weight, very simple, runs on asp.net
mvc and has plenty of ajax goodness.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=cceb7b0e-34ad-4d6c-8435-5d7f51fa8771" />
      </body>
      <title>Name needed for new open source CMS</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,cceb7b0e-34ad-4d6c-8435-5d7f51fa8771.aspx</guid>
      <link>http://www.aboutcode.net/2009/10/10/NameNeededForNewOpenSourceCMS.aspx</link>
      <pubDate>Sat, 10 Oct 2009 17:24:40 GMT</pubDate>
      <description>&lt;p&gt;
Thanks to everyone who left encouraging comments on my &lt;a href="http://www.aboutcode.net/2009/10/08/ShouldIOpenSourceMyNewCMS.aspx"&gt;previous
post about a new CMS&lt;/a&gt; I’ve created.
&lt;/p&gt;
&lt;p&gt;
I have decided that I will be open sourcing the project. However I now need a snappy
name for it. Naming is so hard for some reason!
&lt;/p&gt;
&lt;p&gt;
Any ideas are greatly appreciated. The CMS is light-weight, very simple, runs on asp.net
mvc and has plenty of ajax goodness.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=cceb7b0e-34ad-4d6c-8435-5d7f51fa8771" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,cceb7b0e-34ad-4d6c-8435-5d7f51fa8771.aspx</comments>
      <category>.net</category>
      <category>cms</category>
      <category>mvc</category>
      <category>oss</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=0f434d07-fe80-487b-b7c0-9fdb27dac4a8</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,0f434d07-fe80-487b-b7c0-9fdb27dac4a8.aspx</pingback:target>
      <dc:creator>Andrew Davey</dc:creator>
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,0f434d07-fe80-487b-b7c0-9fdb27dac4a8.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=0f434d07-fe80-487b-b7c0-9fdb27dac4a8</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Over the course of a couple of website developments I created a simple content management
system. I know there are loads our there already, but I wanted something simple and
easy for non-techie users. It runs on ASP.NET MVC, has an elegant extensibility model
and produces clean HTML 5. I very happy with it and plan to use it on all upcoming
simple websites.
</p>
        <p>
The system is file based, so no SQL database is needed. This makes it ideal for running
in shared hosting. It’s perfect for the ~10 page website. But there’s no reason it
can’t scale up to larger sites too.
</p>
        <p>
So I’m obviously enamoured with my own work :) but is it worth sharing? I would love
to get the code out there for people to poke at. However, is it really worth my time
doing so – setting up a project, documentation etc? My recent open sourced work seems
to have taken off like a lead balloon (Snooze, <a href="http://www.assembla.com/wiki/show/hasic">Hasic</a>,
etc)! Do you want to see my new CMS? Or shall I just keep it to myself?
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=0f434d07-fe80-487b-b7c0-9fdb27dac4a8" />
      </body>
      <title>Should I open source my new CMS?</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,0f434d07-fe80-487b-b7c0-9fdb27dac4a8.aspx</guid>
      <link>http://www.aboutcode.net/2009/10/08/ShouldIOpenSourceMyNewCMS.aspx</link>
      <pubDate>Thu, 08 Oct 2009 14:55:37 GMT</pubDate>
      <description>&lt;p&gt;
Over the course of a couple of website developments I created a simple content management
system. I know there are loads our there already, but I wanted something simple and
easy for non-techie users. It runs on ASP.NET MVC, has an elegant extensibility model
and produces clean HTML 5. I very happy with it and plan to use it on all upcoming
simple websites.
&lt;/p&gt;
&lt;p&gt;
The system is file based, so no SQL database is needed. This makes it ideal for running
in shared hosting. It’s perfect for the ~10 page website. But there’s no reason it
can’t scale up to larger sites too.
&lt;/p&gt;
&lt;p&gt;
So I’m obviously enamoured with my own work :) but is it worth sharing? I would love
to get the code out there for people to poke at. However, is it really worth my time
doing so – setting up a project, documentation etc? My recent open sourced work seems
to have taken off like a lead balloon (Snooze, &lt;a href="http://www.assembla.com/wiki/show/hasic"&gt;Hasic&lt;/a&gt;,
etc)! Do you want to see my new CMS? Or shall I just keep it to myself?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=0f434d07-fe80-487b-b7c0-9fdb27dac4a8" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,0f434d07-fe80-487b-b7c0-9fdb27dac4a8.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>cms</category>
      <category>mvc</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=0c0b2ce4-42b7-4b0a-a347-7a3c52bd96cf</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,0c0b2ce4-42b7-4b0a-a347-7a3c52bd96cf.aspx</pingback:target>
      <dc:creator>Andrew Davey</dc:creator>
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,0c0b2ce4-42b7-4b0a-a347-7a3c52bd96cf.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=0c0b2ce4-42b7-4b0a-a347-7a3c52bd96cf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="Hasic - A kick-ass view engine for asp.net mvc" href="http://www.assembla.com/wiki/show/hasic">Hasic</a> is
a kick-ass view engine for <a href="http://www.asp.net/mvc">ASP.NET MVC</a>, with
a completely different approach. It uses VB.NET's XML literals instead of nasty strings
like most other view engines.
</p>
        <p>
That's right, VB! If you are already closing your web browser upon reading that then
shame on you. I'm not saying your whole app is in VB, just the views.
</p>
        <p>
Using VB means this stuff comes for free:
</p>
        <ul>
          <li>
Syntax colouring 
</li>
          <li>
Full intellisense in Visual Studio 
</li>
          <li>
Compiled views 
</li>
          <li>
Extensibility using regular CLR classes, functions etc</li>
        </ul>
        <p>
I’m looking for feedback. So please try out Hasic and let me know what you think –
thanks!
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=0c0b2ce4-42b7-4b0a-a347-7a3c52bd96cf" />
      </body>
      <title>Hasic – A kick-ass view engine for asp.net mvc</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,0c0b2ce4-42b7-4b0a-a347-7a3c52bd96cf.aspx</guid>
      <link>http://www.aboutcode.net/2009/10/08/HasicAKickassViewEngineForAspnetMvc.aspx</link>
      <pubDate>Thu, 08 Oct 2009 14:30:43 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="Hasic - A kick-ass view engine for asp.net mvc" href="http://www.assembla.com/wiki/show/hasic"&gt;Hasic&lt;/a&gt; is
a kick-ass view engine for &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt;, with
a completely different approach. It uses VB.NET's XML literals instead of nasty strings
like most other view engines.
&lt;/p&gt;
&lt;p&gt;
That's right, VB! If you are already closing your web browser upon reading that then
shame on you. I'm not saying your whole app is in VB, just the views.
&lt;/p&gt;
&lt;p&gt;
Using VB means this stuff comes for free:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Syntax colouring 
&lt;/li&gt;
&lt;li&gt;
Full intellisense in Visual Studio 
&lt;/li&gt;
&lt;li&gt;
Compiled views 
&lt;/li&gt;
&lt;li&gt;
Extensibility using regular CLR classes, functions etc&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I’m looking for feedback. So please try out Hasic and let me know what you think –
thanks!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=0c0b2ce4-42b7-4b0a-a347-7a3c52bd96cf" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,0c0b2ce4-42b7-4b0a-a347-7a3c52bd96cf.aspx</comments>
      <category>.net</category>
      <category>mvc</category>
      <category>vb.net</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=cc157a45-2519-48a5-a9c3-6db41d864af9</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,cc157a45-2519-48a5-a9c3-6db41d864af9.aspx</pingback:target>
      <dc:creator>Andrew Davey</dc:creator>
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,cc157a45-2519-48a5-a9c3-6db41d864af9.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=cc157a45-2519-48a5-a9c3-6db41d864af9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Another approach I'm investigating for HTML form generation is using VB's XML literals.
</p>
        <p>
Check out this screencast for a demo: <a title="WSoDB4B9M2" href="http://screencast.com/t/WSoDB4B9M2">http://screencast.com/t/WSoDB4B9M2</a></p>
        <p>
 
</p>
        <p>
XML literals + Expression Trees gives us some serious power!
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=cc157a45-2519-48a5-a9c3-6db41d864af9" />
      </body>
      <title>HTML Forms using VB XML Literals</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,cc157a45-2519-48a5-a9c3-6db41d864af9.aspx</guid>
      <link>http://www.aboutcode.net/2009/03/13/HTMLFormsUsingVBXMLLiterals.aspx</link>
      <pubDate>Fri, 13 Mar 2009 18:44:33 GMT</pubDate>
      <description>&lt;p&gt;
Another approach I'm investigating for HTML form generation is using VB's XML literals.
&lt;/p&gt;
&lt;p&gt;
Check out this screencast for a demo: &lt;a title="WSoDB4B9M2" href="http://screencast.com/t/WSoDB4B9M2"&gt;http://screencast.com/t/WSoDB4B9M2&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
XML literals + Expression Trees gives us some serious power!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=cc157a45-2519-48a5-a9c3-6db41d864af9" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,cc157a45-2519-48a5-a9c3-6db41d864af9.aspx</comments>
      <category>.net</category>
      <category>html</category>
      <category>screencast</category>
      <category>vb.net</category>
      <category>web</category>
      <category>xml</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=f40c1ace-f631-46f2-aaea-fc9efa16a44b</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,f40c1ace-f631-46f2-aaea-fc9efa16a44b.aspx</pingback:target>
      <dc:creator>Andrew Davey</dc:creator>
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,f40c1ace-f631-46f2-aaea-fc9efa16a44b.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=f40c1ace-f631-46f2-aaea-fc9efa16a44b</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
HTML forms seem to be general enough to warrant a better abstraction than manually
creating the HTML, or even using simple HTML helpers. Ideally the semantics of the
form should be enough to generate all the HTML content.
</p>
        <p>
I have been prototyping some ideas in this area. Here is some code that demonstrates
a simple (but incomplete) login form.
</p>
        <style type="text/css">
.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: blue; }
.cb2 { color: #2b91af; }
.cb3 { color: #a31515; }
</style>
        <div class="cf">
          <pre class="cl">
            <span class="cb1">class</span>
            <span class="cb2">LoginData</span>
          </pre>
          <pre class="cl">{</pre>
          <pre class="cl">    <span class="cb1">public</span><span class="cb1">string</span> Username
{ <span class="cb1">get</span>; <span class="cb1">set</span>; }</pre>
          <pre class="cl">    <span class="cb1">public</span><span class="cb1">string</span> Password
{ <span class="cb1">get</span>; <span class="cb1">set</span>; }</pre>
          <pre class="cl">    <span class="cb1">public</span><span class="cb1">bool</span> Persist
{ <span class="cb1">get</span>; <span class="cb1">set</span>; }</pre>
          <pre class="cl">}</pre>
          <pre class="cl"> </pre>
          <pre class="cl"> </pre>
          <pre class="cl">
            <span class="cb1">class</span>
            <span class="cb2">LoginForm</span> : <span class="cb2">Form</span>&lt;<span class="cb2">LoginData</span>&gt;</pre>
          <pre class="cl">{</pre>
          <pre class="cl">    <span class="cb1">public</span> LoginForm()</pre>
          <pre class="cl">    {</pre>
          <pre class="cl">        FieldContainer = <span class="cb1">new</span><span class="cb2">DivFieldContainer</span>();</pre>
          <pre class="cl"> </pre>
          <pre class="cl">        Add(d =&gt; d.Username);</pre>
          <pre class="cl">        Add(d =&gt; d.Password).AsPassword();</pre>
          <pre class="cl">        Add(d =&gt; d.Persist).WithLabel(<span class="cb3">"Stay
logged in on this computer"</span>);</pre>
          <pre class="cl">    }</pre>
          <pre class="cl">}</pre>
          <pre class="cl"> </pre>
          <pre class="cl">
            <span class="cb1">class</span>
            <span class="cb2">Program</span>
          </pre>
          <pre class="cl">{</pre>
          <pre class="cl">    <span class="cb1">static</span><span class="cb1">void</span> Main(<span class="cb1">string</span>[]
args)</pre>
          <pre class="cl">    {</pre>
          <pre class="cl">        <span class="cb1">var</span> data
= <span class="cb1">new</span><span class="cb2">LoginData</span>() { Username = <span class="cb3">"test"</span> };</pre>
          <pre class="cl">        <span class="cb1">var</span> form
= <span class="cb1">new</span><span class="cb2">LoginForm</span>();</pre>
          <pre class="cl"> </pre>
          <pre class="cl">        <span class="cb1">var</span> html
= form.Create(data);</pre>
          <pre class="cl">        <span class="cb2">Console</span>.WriteLine(html.ToString());</pre>
          <pre class="cl">    }</pre>
          <pre class="cl">}</pre>
        </div>
        <p>
This generates the following HTML. 
</p>
        <pre>&lt;form method="POST" action="http://localhost/"&gt;<br />
  &lt;div&gt;<br />
    &lt;label for="Username"&gt;Username&lt;/label&gt;<br />
    &lt;input id="Username" type="text" name="Username" value="test"
/&gt;<br />
  &lt;/div&gt;<br />
  &lt;div&gt;<br />
    &lt;label for="Password"&gt;Password&lt;/label&gt;<br />
    &lt;input id="Password" type="password" name="Password" /&gt;<br />
  &lt;/div&gt;<br />
  &lt;div&gt;<br />
    &lt;input id="Persist" type="checkbox" name="Persist" /&gt;<br />
    &lt;label for="Persist"&gt;Stay logged in on this computer&lt;/label&gt;<br />
  &lt;/div&gt;<br />
&lt;/form&gt;</pre>
        <p>
There is a clear separation of the data from the form meta-data. This lets me do interesting
things like applying conventions, for example, the generation of label text from property
names. I want to use mostly global conventions for a form, and then override a few
specific fields where needed. 
</p>
        <p>
I think validation can also fit nicely into this approach. Validation logic can be
put on the data model. The form model can then specify how errors are added to the
HTML.
</p>
        <p>
Has anyone else seen anything like this before? I don’t want the reinvent the wheel.
Or at least I can steal some good ideas ;)
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=f40c1ace-f631-46f2-aaea-fc9efa16a44b" />
      </body>
      <title>Automatic HTML Forms</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,f40c1ace-f631-46f2-aaea-fc9efa16a44b.aspx</guid>
      <link>http://www.aboutcode.net/2009/03/13/AutomaticHTMLForms.aspx</link>
      <pubDate>Fri, 13 Mar 2009 11:51:16 GMT</pubDate>
      <description>&lt;p&gt;
HTML forms seem to be general enough to warrant a better abstraction than manually
creating the HTML, or even using simple HTML helpers. Ideally the semantics of the
form should be enough to generate all the HTML content.
&lt;/p&gt;
&lt;p&gt;
I have been prototyping some ideas in this area. Here is some code that demonstrates
a simple (but incomplete) login form.
&lt;/p&gt;
&lt;style type="text/css"&gt;
.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: blue; }
.cb2 { color: #2b91af; }
.cb3 { color: #a31515; }
&lt;/style&gt;
&lt;div class="cf"&gt;&lt;pre class="cl"&gt;&lt;span class="cb1"&gt;class&lt;/span&gt; &lt;span class="cb2"&gt;LoginData&lt;/span&gt;&lt;/pre&gt;&lt;pre class="cl"&gt;{&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb1"&gt;public&lt;/span&gt; &lt;span class="cb1"&gt;string&lt;/span&gt; Username
{ &lt;span class="cb1"&gt;get&lt;/span&gt;; &lt;span class="cb1"&gt;set&lt;/span&gt;; }&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb1"&gt;public&lt;/span&gt; &lt;span class="cb1"&gt;string&lt;/span&gt; Password
{ &lt;span class="cb1"&gt;get&lt;/span&gt;; &lt;span class="cb1"&gt;set&lt;/span&gt;; }&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb1"&gt;public&lt;/span&gt; &lt;span class="cb1"&gt;bool&lt;/span&gt; Persist
{ &lt;span class="cb1"&gt;get&lt;/span&gt;; &lt;span class="cb1"&gt;set&lt;/span&gt;; }&lt;/pre&gt;&lt;pre class="cl"&gt;}&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="cl"&gt;&lt;span class="cb1"&gt;class&lt;/span&gt; &lt;span class="cb2"&gt;LoginForm&lt;/span&gt; : &lt;span class="cb2"&gt;Form&lt;/span&gt;&amp;lt;&lt;span class="cb2"&gt;LoginData&lt;/span&gt;&amp;gt;&lt;/pre&gt;&lt;pre class="cl"&gt;{&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb1"&gt;public&lt;/span&gt; LoginForm()&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FieldContainer = &lt;span class="cb1"&gt;new&lt;/span&gt; &lt;span class="cb2"&gt;DivFieldContainer&lt;/span&gt;();&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Add(d =&amp;gt; d.Username);&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Add(d =&amp;gt; d.Password).AsPassword();&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Add(d =&amp;gt; d.Persist).WithLabel(&lt;span class="cb3"&gt;"Stay
logged in on this computer"&lt;/span&gt;);&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre class="cl"&gt;}&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="cl"&gt;&lt;span class="cb1"&gt;class&lt;/span&gt; &lt;span class="cb2"&gt;Program&lt;/span&gt;&lt;/pre&gt;&lt;pre class="cl"&gt;{&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb1"&gt;static&lt;/span&gt; &lt;span class="cb1"&gt;void&lt;/span&gt; Main(&lt;span class="cb1"&gt;string&lt;/span&gt;[]
args)&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb1"&gt;var&lt;/span&gt; data
= &lt;span class="cb1"&gt;new&lt;/span&gt; &lt;span class="cb2"&gt;LoginData&lt;/span&gt;() { Username = &lt;span class="cb3"&gt;"test"&lt;/span&gt; };&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb1"&gt;var&lt;/span&gt; form
= &lt;span class="cb1"&gt;new&lt;/span&gt; &lt;span class="cb2"&gt;LoginForm&lt;/span&gt;();&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb1"&gt;var&lt;/span&gt; html
= form.Create(data);&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="cb2"&gt;Console&lt;/span&gt;.WriteLine(html.ToString());&lt;/pre&gt;&lt;pre class="cl"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;pre class="cl"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
This generates the following HTML. &lt;pre&gt;&amp;lt;form method="POST" action="http://localhost/"&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;div&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;label for="Username"&amp;gt;Username&amp;lt;/label&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;input id="Username" type="text" name="Username" value="test"
/&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;/div&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;div&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;label for="Password"&amp;gt;Password&amp;lt;/label&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;input id="Password" type="password" name="Password" /&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;/div&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;div&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;input id="Persist" type="checkbox" name="Persist" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;label for="Persist"&amp;gt;Stay logged in on this computer&amp;lt;/label&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;/div&amp;gt;&lt;br&gt;
&amp;lt;/form&amp;gt;&lt;/pre&gt;
&lt;p&gt;
There is a clear separation of the data from the form meta-data. This lets me do interesting
things like applying conventions, for example, the generation of label text from property
names. I want to use mostly global conventions for a form, and then override a few
specific fields where needed. 
&lt;p&gt;
I think validation can also fit nicely into this approach. Validation logic can be
put on the data model. The form model can then specify how errors are added to the
HTML.
&lt;/p&gt;
&lt;p&gt;
Has anyone else seen anything like this before? I don’t want the reinvent the wheel.
Or at least I can steal some good ideas ;)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=f40c1ace-f631-46f2-aaea-fc9efa16a44b" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,f40c1ace-f631-46f2-aaea-fc9efa16a44b.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>html</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad.aspx</pingback:target>
      <dc:creator>Andrew Davey</dc:creator>
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Don't call SmtpClient.SendMail directly within your controller actions because it
directly couples your controller to SmtpClient.
</p>
        <p>
Don't even create an interface IMailer and wrapping implementation of this to SmtpClient.
</p>
        <p>
Instead, create a new ActionResult subclass called EmailResult. Make this class have
the properties From, To, Subject and BodyData. In the ExecuteResult method use the
ViewEngine infrastructure to render a view of the BodyData into your own StringWriter.
You can then send the resulting content via email using SmtpClient.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad" />
      </body>
      <title>Email ActionResult in ASP.NET MVC</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad.aspx</guid>
      <link>http://www.aboutcode.net/2009/01/19/EmailActionResultInASPNETMVC.aspx</link>
      <pubDate>Mon, 19 Jan 2009 16:39:44 GMT</pubDate>
      <description>&lt;p&gt;
Don't call SmtpClient.SendMail directly within your controller actions because it
directly couples your controller to SmtpClient.
&lt;/p&gt;
&lt;p&gt;
Don't even create an interface IMailer and wrapping implementation of this to SmtpClient.
&lt;/p&gt;
&lt;p&gt;
Instead, create a new ActionResult subclass called EmailResult. Make this class have
the properties From, To, Subject and BodyData. In the ExecuteResult method use the
ViewEngine infrastructure to render a view of the BodyData into your own StringWriter.
You can then send the resulting content via email using SmtpClient.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,c9d9ee2e-555e-4b7f-8509-8bd8a9dcc5ad.aspx</comments>
      <category>.net</category>
      <category>asp</category>
      <category>mvc</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=ccfe3888-bdd7-4f13-b704-53f6e5cf5020</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,ccfe3888-bdd7-4f13-b704-53f6e5cf5020.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,ccfe3888-bdd7-4f13-b704-53f6e5cf5020.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ccfe3888-bdd7-4f13-b704-53f6e5cf5020</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Avoid using HttpContext in controller actions to make testing much easier. Therefore
all inputs to an action needs to be passed as parameters. In my new REST framework
that builds on ASP.NET MVC I have created some useful model binders to make this easy.
</p>
        <p>
          <font face="Courier New">[ResourceUriTemplate("")]<br />
public class RootUri : ResourceUri<br />
{<br />
    public ResourceResponse Get([HttpCookie] string visited, [AppSetting]
int visitTimeout)<br />
    { 
<br />
    ...<br />
    }<br />
}</font>
        </p>
        <p>
The HttpCookieAttribute looks for a cookie called "visited". The AppSettingAttribute
looks in web.config for an appSetting with the key "visitTimeout". The method is now
easy to test and has very readable definition. :) 
</p>
        <p>
  
</p>
        <p>
Both attributes will cast the raw string found into the required type by using a TypeConverter. 
</p>
        <p>
The AppSettingAttribute constructor can also take a key name if you want something
different from the parameter name. 
</p>
        <p>
The code is in <a href="http://svn2.assembla.com/svn/snooze/branches/aspnet" target="_blank">SubVersion</a>,
but I'll repeat some here to show just how easy it was: 
</p>
        <p>
          <font face="Courier New">namespace Snooze<br />
{<br />
    public class AppSettingAttribute : CustomModelBinderAttribute<br />
    {<br />
        public AppSettingAttribute()<br />
        {<br />
        } </font>
        </p>
        <p>
          <font face="Courier New">        public AppSettingAttribute(string
key)<br />
        {<br />
            _key = key;<br />
        } </font>
        </p>
        <p>
          <font face="Courier New">        string _key; </font>
        </p>
        <p>
          <font face="Courier New">        public override
IModelBinder GetBinder()<br />
        {<br />
            return new AppSettingModelBinder(_key);<br />
        }<br />
    } </font>
        </p>
        <p>
          <font face="Courier New">    public class AppSettingModelBinder : IModelBinder<br />
    {<br />
        public AppSettingModelBinder(string key)<br />
        {<br />
            _key = key;<br />
        } </font>
        </p>
        <p>
          <font face="Courier New">        string _key; </font>
        </p>
        <p>
          <font face="Courier New">        public ModelBinderResult
BindModel(ModelBindingContext bindingContext)<br />
        {<br />
            string setting
= WebConfigurationManager.AppSettings[_key ?? bindingContext.ModelName];<br />
            object value;<br />
            if (bindingContext.ModelType
== typeof(string))<br />
            {<br />
               
value = setting;<br />
            }<br />
            else<br />
            {<br />
               
value = TypeDescriptor.GetConverter(bindingContext.ModelType).ConvertFromString(setting);<br />
            }<br />
            return new ModelBinderResult(value);<br />
        }<br />
    }<br />
}</font>
        </p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=ccfe3888-bdd7-4f13-b704-53f6e5cf5020" />
      </body>
      <title>Model Binders for HttpCookie and AppSetting</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,ccfe3888-bdd7-4f13-b704-53f6e5cf5020.aspx</guid>
      <link>http://www.aboutcode.net/2008/12/08/ModelBindersForHttpCookieAndAppSetting.aspx</link>
      <pubDate>Mon, 08 Dec 2008 20:55:53 GMT</pubDate>
      <description>&lt;p&gt;
Avoid using HttpContext in controller actions to make testing much easier. Therefore
all inputs to an action needs to be passed as parameters. In my new REST framework
that builds on ASP.NET MVC I have created some useful model binders to make this easy.
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;[ResourceUriTemplate("")]&lt;br&gt;
public class RootUri : ResourceUri&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public ResourceResponse Get([HttpCookie] string visited, [AppSetting]
int visitTimeout)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; { 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;/font&gt; 
&lt;p&gt;
The HttpCookieAttribute looks for a cookie called "visited". The AppSettingAttribute
looks in web.config for an appSetting with the key "visitTimeout". The method is now
easy to test and has very readable definition. :) 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Both attributes will cast the raw string found into the required type by using a TypeConverter. 
&lt;p&gt;
The AppSettingAttribute constructor can also take a key name if you want something
different from the parameter name. 
&lt;p&gt;
The code is in &lt;a href="http://svn2.assembla.com/svn/snooze/branches/aspnet" target="_blank"&gt;SubVersion&lt;/a&gt;,
but I'll repeat some here to show just how easy it was: 
&lt;p&gt;
&lt;font face="Courier New"&gt;namespace Snooze&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public class AppSettingAttribute : CustomModelBinderAttribute&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public AppSettingAttribute()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public AppSettingAttribute(string
key)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _key = key;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string _key; &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override
IModelBinder GetBinder()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new AppSettingModelBinder(_key);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class AppSettingModelBinder : IModelBinder&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public AppSettingModelBinder(string key)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _key = key;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string _key; &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ModelBinderResult
BindModel(ModelBindingContext bindingContext)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string setting
= WebConfigurationManager.AppSettings[_key ?? bindingContext.ModelName];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (bindingContext.ModelType
== typeof(string))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&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;
value = setting;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&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;
value = TypeDescriptor.GetConverter(bindingContext.ModelType).ConvertFromString(setting);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new ModelBinderResult(value);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=ccfe3888-bdd7-4f13-b704-53f6e5cf5020" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,ccfe3888-bdd7-4f13-b704-53f6e5cf5020.aspx</comments>
      <category>.net</category>
      <category>mvc</category>
      <category>REST</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=5c58c4bc-9e1a-4eac-87e0-466d78c7bfcf</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,5c58c4bc-9e1a-4eac-87e0-466d78c7bfcf.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,5c58c4bc-9e1a-4eac-87e0-466d78c7bfcf.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=5c58c4bc-9e1a-4eac-87e0-466d78c7bfcf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Filters in ASP.NET MVC provide a great way to attach functionality around controllers.
By building on top of the MVC framework, my ResourceUri class (which inherits from
Controller) gets all the filter goodness as well.
</p>
        <p>
My library also has a SubResourceUri class. Any filters applied to the parent ResourceUri
are also executed for the SubResourceUri.
</p>
        <p>
          <font face="Courier New">[ResourceUriTemplate("customers/{CustomerId}")]<br />
[MyLoggingFilter]<br />
public class CustomerUri : ResourceUri { ... }<br /><br />
[ResourceUriTemplate("orders/{OrderId}")]<br />
public class OrderUri : SubResourceUri&lt;CustomerUri&gt; { ...}</font>
        </p>
        <p>
For example, when we GET an order the filter still catches the request and outputs
logging information.
</p>
        <p>
Another use is authorization. You can place an authorization filter on top level URI
and it will protect all sub-URIs beneath it. 
</p>
        <p>
 
</p>
        <p>
Keep track of the latest developments on the code here: <a title="http://svn2.assembla.com/svn/snooze/branches/aspnet" href="http://svn2.assembla.com/svn/snooze/branches/aspnet">http://svn2.assembla.com/svn/snooze/branches/aspnet</a></p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=5c58c4bc-9e1a-4eac-87e0-466d78c7bfcf" />
      </body>
      <title>Sub-resources and filters</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,5c58c4bc-9e1a-4eac-87e0-466d78c7bfcf.aspx</guid>
      <link>http://www.aboutcode.net/2008/12/07/SubresourcesAndFilters.aspx</link>
      <pubDate>Sun, 07 Dec 2008 21:34:25 GMT</pubDate>
      <description>&lt;p&gt;
Filters in ASP.NET MVC provide a great way to attach functionality around controllers.
By building on top of the MVC framework, my ResourceUri class (which inherits from
Controller) gets all the filter goodness as well.
&lt;/p&gt;
&lt;p&gt;
My library also has a SubResourceUri class. Any filters applied to the parent ResourceUri
are also executed for the SubResourceUri.
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;[ResourceUriTemplate("customers/{CustomerId}")]&lt;br&gt;
[MyLoggingFilter]&lt;br&gt;
public class CustomerUri : ResourceUri { ... }&lt;br&gt;
&lt;br&gt;
[ResourceUriTemplate("orders/{OrderId}")]&lt;br&gt;
public class OrderUri : SubResourceUri&amp;lt;CustomerUri&amp;gt; { ...}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
For example, when we GET an order the filter still catches the request and outputs
logging information.
&lt;/p&gt;
&lt;p&gt;
Another use is authorization. You can place an authorization filter on top level URI
and it will protect all sub-URIs beneath it. 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Keep track of the latest developments on the code here: &lt;a title="http://svn2.assembla.com/svn/snooze/branches/aspnet" href="http://svn2.assembla.com/svn/snooze/branches/aspnet"&gt;http://svn2.assembla.com/svn/snooze/branches/aspnet&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=5c58c4bc-9e1a-4eac-87e0-466d78c7bfcf" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,5c58c4bc-9e1a-4eac-87e0-466d78c7bfcf.aspx</comments>
      <category>.net</category>
      <category>mvc</category>
      <category>REST</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=248f1839-a7b8-4f6e-a03f-9b2f9d8cea8b</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,248f1839-a7b8-4f6e-a03f-9b2f9d8cea8b.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,248f1839-a7b8-4f6e-a03f-9b2f9d8cea8b.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=248f1839-a7b8-4f6e-a03f-9b2f9d8cea8b</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Continued work on my resource-oriented library for ASP.NET MVC has expanded to include
an <a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx" target="_blank">XDocument</a> based
view engine for ASP.NET MVC.
</p>
        <p>
This means we can now use VB.NET XML literals to define XHTML views (or any XML views).
</p>
        <p>
Get the <a href="http://svn2.assembla.com/svn/snooze/branches/aspnet" target="_blank">latest
from SVN</a>.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=248f1839-a7b8-4f6e-a03f-9b2f9d8cea8b" />
      </body>
      <title>XDocument View Engine for ASP.NET MVC</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,248f1839-a7b8-4f6e-a03f-9b2f9d8cea8b.aspx</guid>
      <link>http://www.aboutcode.net/2008/11/30/XDocumentViewEngineForASPNETMVC.aspx</link>
      <pubDate>Sun, 30 Nov 2008 22:49:44 GMT</pubDate>
      <description>&lt;p&gt;
Continued work on my resource-oriented library for ASP.NET MVC has expanded to include
an &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx" target="_blank"&gt;XDocument&lt;/a&gt; based
view engine for ASP.NET MVC.
&lt;/p&gt;
&lt;p&gt;
This means we can now use VB.NET XML literals to define XHTML views (or any XML views).
&lt;/p&gt;
&lt;p&gt;
Get the &lt;a href="http://svn2.assembla.com/svn/snooze/branches/aspnet" target="_blank"&gt;latest
from SVN&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=248f1839-a7b8-4f6e-a03f-9b2f9d8cea8b" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,248f1839-a7b8-4f6e-a03f-9b2f9d8cea8b.aspx</comments>
      <category>.net</category>
      <category>html</category>
      <category>mvc</category>
      <category>REST</category>
      <category>vb.net</category>
      <category>web</category>
      <category>xml</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=ed499724-c6b0-43d5-892b-34ee7bdbab6a</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,ed499724-c6b0-43d5-892b-34ee7bdbab6a.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,ed499724-c6b0-43d5-892b-34ee7bdbab6a.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ed499724-c6b0-43d5-892b-34ee7bdbab6a</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Now that the ASP.NET MVC API has settled down I decided to bring some of my ideas
about REST and resource-oriented programming to it. 
</p>
        <p>
The following screencast shows my current prototype in action:<br /><a href="http://www.aboutcode.net/screencasts/snooze-aspnet-mvc.wmv">http://www.aboutcode.net/screencasts/snooze-aspnet-mvc.wmv</a></p>
        <p>
I'm keen for comments and feedback. 
</p>
        <p>
The source code is currently available via SVN here:<br /><a href="http://svn2.assembla.com/svn/snooze/branches/aspnet">http://svn2.assembla.com/svn/snooze/branches/aspnet</a></p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=ed499724-c6b0-43d5-892b-34ee7bdbab6a" />
      </body>
      <title>New Resource-Oriented Library for ASP.NET MVC</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,ed499724-c6b0-43d5-892b-34ee7bdbab6a.aspx</guid>
      <link>http://www.aboutcode.net/2008/11/26/NewResourceOrientedLibraryForASPNETMVC.aspx</link>
      <pubDate>Wed, 26 Nov 2008 03:23:02 GMT</pubDate>
      <description>&lt;p&gt;
Now that the ASP.NET MVC API has settled down I decided to bring some of my ideas
about REST and resource-oriented programming to it. 
&lt;p&gt;
The following screencast shows my current prototype in action:&lt;br&gt;
&lt;a href="http://www.aboutcode.net/screencasts/snooze-aspnet-mvc.wmv"&gt;http://www.aboutcode.net/screencasts/snooze-aspnet-mvc.wmv&lt;/a&gt; 
&lt;p&gt;
I'm keen for comments and feedback. 
&lt;p&gt;
The source code is currently available via SVN here:&lt;br&gt;
&lt;a href="http://svn2.assembla.com/svn/snooze/branches/aspnet"&gt;http://svn2.assembla.com/svn/snooze/branches/aspnet&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=ed499724-c6b0-43d5-892b-34ee7bdbab6a" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,ed499724-c6b0-43d5-892b-34ee7bdbab6a.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>mvc</category>
      <category>REST</category>
      <category>screencast</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=cd7d5d9e-871d-424e-b24c-586501b2ed95</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,cd7d5d9e-871d-424e-b24c-586501b2ed95.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,cd7d5d9e-871d-424e-b24c-586501b2ed95.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=cd7d5d9e-871d-424e-b24c-586501b2ed95</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sending data from a resource to a view in a strongly-typed, but syntactically lightweight
manner is not possible with C# or VB.NET.
</p>
        <p>
So check out this <a href="http://screencast.com/t/ByvBTDhJ">screencast</a> of the
new "render" macro in <a href="http://www.assembla.com/wiki/show/nrest">NRest</a>!
</p>
        <p>
In a nutshell, my resource looks like:
</p>
        <p>
          <font face="Courier New">[Resource("")]<br />
public class RootResource<br />
{<br />
    public Get() : void<br />
    {<br />
        def test = 42;<br />
        render (Foo = "Hello", Bar = "World", test);<br />
    }<br />
}</font>
        </p>
        <p>
My VB.NET view looks like: 
</p>
        <p>
          <font face="Courier New">Public Class RootPage<br />
    Inherits Page(Of RootPageContent) </font>
        </p>
        <p>
          <font face="Courier New">    Public Overrides Function GetHtml() As
XElement<br />
        Return _<br />
        &lt;html&gt;<br />
            &lt;body&gt;&lt;%=
Content.Foo %&gt;, &lt;%= Content.Bar %&gt;&lt;/body&gt;<br />
        &lt;/html&gt;<br />
    End Function 
<br />
End Class</font>
        </p>
        <p>
The RootPageContent DTO class is generated at compile time by the render macro. Everything
is strongly-typed. <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=cd7d5d9e-871d-424e-b24c-586501b2ed95" /></p>
      </body>
      <title>Strongly Typed View Data in NRest</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,cd7d5d9e-871d-424e-b24c-586501b2ed95.aspx</guid>
      <link>http://www.aboutcode.net/2008/07/13/StronglyTypedViewDataInNRest.aspx</link>
      <pubDate>Sun, 13 Jul 2008 14:27:17 GMT</pubDate>
      <description>&lt;p&gt;
Sending data from a resource to a view in a strongly-typed, but syntactically lightweight
manner is not possible with C# or VB.NET.
&lt;/p&gt;
&lt;p&gt;
So check out this &lt;a href="http://screencast.com/t/ByvBTDhJ"&gt;screencast&lt;/a&gt; of the
new "render" macro in &lt;a href="http://www.assembla.com/wiki/show/nrest"&gt;NRest&lt;/a&gt;!
&lt;/p&gt;
&lt;p&gt;
In a nutshell, my resource looks like:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;[Resource("")]&lt;br&gt;
public class RootResource&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public Get() : void&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def test = 42;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; render (Foo = "Hello", Bar = "World", test);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;/font&gt; 
&lt;p&gt;
My VB.NET view looks like: 
&lt;p&gt;
&lt;font face="Courier New"&gt;Public Class RootPage&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Inherits Page(Of RootPageContent) &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Overrides Function GetHtml() As
XElement&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return _&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;html&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;body&amp;gt;&amp;lt;%=
Content.Foo %&amp;gt;, &amp;lt;%= Content.Bar %&amp;gt;&amp;lt;/body&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/html&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; End Function 
&lt;br&gt;
End Class&lt;/font&gt; 
&lt;p&gt;
The RootPageContent DTO class is generated at compile time by the render macro. Everything
is strongly-typed. &lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=cd7d5d9e-871d-424e-b24c-586501b2ed95" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,cd7d5d9e-871d-424e-b24c-586501b2ed95.aspx</comments>
      <category>.net</category>
      <category>dsl</category>
      <category>macro</category>
      <category>nemerle</category>
      <category>nrest</category>
      <category>REST</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=18337f8d-e357-4017-835b-d5064c48d444</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,18337f8d-e357-4017-835b-d5064c48d444.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,18337f8d-e357-4017-835b-d5064c48d444.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=18337f8d-e357-4017-835b-d5064c48d444</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This is a very quick video showing the work I've been doing with <a href="http://nemerle.org/">Nemerle</a>,
ASP.NET routing and VB 9 XML literals.<br />
I'm trying to find the most efficient way to create RESTful web applications. I'm
willing to use all the tools in the box and even make my own to achieve this. 
</p>
        <p>
          <object id="NRest-001" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" height="695" width="1008" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
            <param name="_cx" value="14552" />
            <param name="_cy" value="10583" />
            <param name="FlashVars" value="" />
            <param name="Movie" value="http://www.aboutcode.net/screencasts/nrest-001.swf" />
            <param name="Src" value="http://www.aboutcode.net/screencasts/nrest-001.swf" />
            <param name="WMode" value="Window" />
            <param name="Play" value="0" />
            <param name="Loop" value="-1" />
            <param name="Quality" value="High" />
            <param name="SAlign" value="" />
            <param name="Menu" value="-1" />
            <param name="Base" value="" />
            <param name="AllowScriptAccess" value="" />
            <param name="Scale" value="NoScale" />
            <param name="DeviceFont" value="0" />
            <param name="EmbedMovie" value="0" />
            <param name="BGColor" value="FFFFFF" />
            <param name="SWRemote" value="" />
            <param name="MovieData" value="" />
            <param name="SeamlessTabbing" value="1" />
            <param name="Profile" value="0" />
            <param name="ProfileAddress" value="" />
            <param name="ProfilePort" value="0" />
            <param name="AllowNetworking" value="all" />
            <param name="AllowFullScreen" value="false" />
            <embed src="http://www.aboutcode.net/screencasts/nrest-001.swf" quality="high" bgcolor="#FFFFFF" width="1008" height="695" name="NRest-001" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
            </embed>
          </object>
        </p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=18337f8d-e357-4017-835b-d5064c48d444" />
      </body>
      <title>Quick NRest Video</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,18337f8d-e357-4017-835b-d5064c48d444.aspx</guid>
      <link>http://www.aboutcode.net/2008/07/02/QuickNRestVideo.aspx</link>
      <pubDate>Wed, 02 Jul 2008 10:19:24 GMT</pubDate>
      <description>&lt;p&gt;
This is a very quick video showing the work I've been doing with &lt;a href="http://nemerle.org/"&gt;Nemerle&lt;/a&gt;,
ASP.NET routing and VB 9 XML literals.&lt;br&gt;
I'm trying to find the most efficient way to create RESTful web applications. I'm
willing to use all the tools in the box and even make my own to achieve this. 
&lt;/p&gt;
&lt;p&gt;
&lt;object id="NRest-001" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" height="695" width="1008" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"&gt;
&lt;param name="_cx" value="14552"&gt;
&lt;param name="_cy" value="10583"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.aboutcode.net/screencasts/nrest-001.swf"&gt;
&lt;param name="Src" value="http://www.aboutcode.net/screencasts/nrest-001.swf"&gt;
&lt;param name="WMode" value="Window"&gt;
&lt;param name="Play" value="0"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value=""&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value=""&gt;
&lt;param name="Scale" value="NoScale"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value="FFFFFF"&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="false"&gt;
&lt;embed src="http://www.aboutcode.net/screencasts/nrest-001.swf" quality="high" bgcolor="#FFFFFF" width="1008" height="695" name="NRest-001" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=18337f8d-e357-4017-835b-d5064c48d444" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,18337f8d-e357-4017-835b-d5064c48d444.aspx</comments>
      <category>.net</category>
      <category>nemerle</category>
      <category>REST</category>
      <category>screencast</category>
      <category>vb.net</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=77343809-58ef-46f7-b44b-2d002e72c4df</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,77343809-58ef-46f7-b44b-2d002e72c4df.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,77343809-58ef-46f7-b44b-2d002e72c4df.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=77343809-58ef-46f7-b44b-2d002e72c4df</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
        </p>
        <p>
A demo website using my Hasic view engine for ASP.NET MVC.
</p>
        <p>
          <a href="http://www.aboutcode.net/content/binary/HasicDemo.zip">HasicDemo.zip (275.95
KB)</a>
        </p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=77343809-58ef-46f7-b44b-2d002e72c4df" />
      </body>
      <title>Hasic Demo</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,77343809-58ef-46f7-b44b-2d002e72c4df.aspx</guid>
      <link>http://www.aboutcode.net/2008/05/10/HasicDemo.aspx</link>
      <pubDate>Sat, 10 May 2008 16:37:41 GMT</pubDate>
      <description>&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
A demo website using my Hasic view engine for ASP.NET MVC.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.aboutcode.net/content/binary/HasicDemo.zip"&gt;HasicDemo.zip (275.95
KB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=77343809-58ef-46f7-b44b-2d002e72c4df" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,77343809-58ef-46f7-b44b-2d002e72c4df.aspx</comments>
      <category>.net</category>
      <category>vb.net</category>
      <category>web</category>
      <category>hasic</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=804bfcdb-830d-4e0a-9117-3b0f1ac70b5f</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,804bfcdb-830d-4e0a-9117-3b0f1ac70b5f.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,804bfcdb-830d-4e0a-9117-3b0f1ac70b5f.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=804bfcdb-830d-4e0a-9117-3b0f1ac70b5f</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have started using <a href="http://ninject.org/">Ninject</a> a dependency injection
framework for .NET. I find it very easy to use and recommend that people take a look.
</p>
        <p>
Something in particular that I found useful is the ability to bind open generic types.
</p>
        <p>
          <font face="Courier New" size="2">class Program<br />
{<br />
    static void Main(string[] args)<br />
    {<br />
        var k = new StandardKernel(new MyModule()); </font>
        </p>
        <p>
          <font face="Courier New" size="2">        var di
= k.Get&lt;Data&lt;int&gt;&gt;();<br />
        di.Content = 14;<br />
        Console.WriteLine(di.Content); </font>
        </p>
        <p>
          <font face="Courier New" size="2">        var ds
= k.Get&lt;Data&lt;string&gt;&gt;();<br />
        ds.Content = "hello";<br />
        Console.WriteLine(ds.Content);<br />
    }<br />
} </font>
        </p>
        <p>
          <font face="Courier New" size="2">class MyModule : StandardModule<br />
{<br />
    public override void Load()<br />
    {<br />
        Bind(typeof(IData&lt;&gt;)).To(typeof(Data&lt;&gt;));<br />
    }<br />
} </font>
        </p>
        <p>
          <font face="Courier New" size="2">class Data&lt;T&gt; : IData&lt;T&gt;<br />
{<br />
    public T Content { get; set; }<br />
} </font>
        </p>
        <p>
          <font face="Courier New" size="2">interface IData&lt;T&gt;<br />
{<br />
    T Content { get; set; }<br />
}</font>
        </p>
        <p>
Very cool!
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=804bfcdb-830d-4e0a-9117-3b0f1ac70b5f" />
      </body>
      <title>Ninject Open Generic Types</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,804bfcdb-830d-4e0a-9117-3b0f1ac70b5f.aspx</guid>
      <link>http://www.aboutcode.net/2008/04/29/NinjectOpenGenericTypes.aspx</link>
      <pubDate>Tue, 29 Apr 2008 18:36:59 GMT</pubDate>
      <description>&lt;p&gt;
I have started using &lt;a href="http://ninject.org/"&gt;Ninject&lt;/a&gt; a dependency injection
framework for .NET. I find it very easy to use and recommend that people take a look.
&lt;/p&gt;
&lt;p&gt;
Something in particular that I found useful is the ability to bind open generic types.
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New" size="2"&gt;class Program&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; static void Main(string[] args)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var k = new StandardKernel(new MyModule()); &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var di
= k.Get&amp;lt;Data&amp;lt;int&amp;gt;&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; di.Content = 14;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(di.Content); &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var ds
= k.Get&amp;lt;Data&amp;lt;string&amp;gt;&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ds.Content = "hello";&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(ds.Content);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
} &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New" size="2"&gt;class MyModule : StandardModule&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void Load()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bind(typeof(IData&amp;lt;&amp;gt;)).To(typeof(Data&amp;lt;&amp;gt;));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
} &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New" size="2"&gt;class Data&amp;lt;T&amp;gt; : IData&amp;lt;T&amp;gt;&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public T Content { get; set; }&lt;br&gt;
} &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New" size="2"&gt;interface IData&amp;lt;T&amp;gt;&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; T Content { get; set; }&lt;br&gt;
}&lt;/font&gt; 
&lt;p&gt;
Very cool!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=804bfcdb-830d-4e0a-9117-3b0f1ac70b5f" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,804bfcdb-830d-4e0a-9117-3b0f1ac70b5f.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>ninject</category>
      <category>programming</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=6c1cb700-c584-43b3-9fb2-7ee0fe1ae3cd</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,6c1cb700-c584-43b3-9fb2-7ee0fe1ae3cd.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,6c1cb700-c584-43b3-9fb2-7ee0fe1ae3cd.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6c1cb700-c584-43b3-9fb2-7ee0fe1ae3cd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've seen people testing that RenderView is called by a controller by inheriting into
a "testable" controller. Madness!
</p>
        <p>
RenderView is just a convenience method that calls to IViewEngine, so why not just
test expectations on that with a mock? We basically want to test that the correct
ViewContext is sent to the RenderView method of the view engine.
</p>
        <p>
This is my test:
</p>
        <p>
          <font face="Courier New">[TestFixture]<br />
public class HomeControllerTests : ControllerTestsBase&lt;HomeController&gt;<br />
{<br />
    public override HomeController CreateController()<br />
    {<br />
        return new HomeController();<br />
    } </font>
        </p>
        <p>
          <font face="Courier New">    [Test]<br />
    public void Renders_Index()<br />
    {<br />
        var render = ExpectRenderView(); </font>
        </p>
        <p>
          <font face="Courier New">        Controller.Index(); </font>
        </p>
        <p>
          <font face="Courier New">        Assert.That(render.Data.ViewName,
Is.EqualTo("Index"));<br />
    }<br />
}</font>
        </p>
        <p>
I don't think we can get more straight forward than that!
</p>
        <p>
This is my test base class:<br />
(I'm using Moq as the mock framework.)
</p>
        <p>
          <font face="Courier New">public abstract class ControllerTestsBase&lt;T&gt;<br />
    where T : Controller<br />
{<br />
    public T Controller;<br />
    public Mock&lt;IViewEngine&gt; ViewEngine; </font>
        </p>
        <p>
          <font face="Courier New">    [SetUp]<br />
    public virtual void SetUp()<br />
    {<br />
        Controller = CreateController();<br />
        ViewEngine = new Mock&lt;IViewEngine&gt;();<br />
        Controller.ViewEngine = ViewEngine.Object; </font>
        </p>
        <p>
          <font face="Courier New">        Controller.ControllerContext
= new Mock&lt;ControllerContext&gt;(new Mock&lt;HttpContextBase&gt;().Object, new
RouteData(), Controller).Object;<br />
    } </font>
        </p>
        <p>
          <font face="Courier New">    public abstract T CreateController(); </font>
        </p>
        <p>
          <font face="Courier New">    public RenderCall&lt;ViewContext&gt; ExpectRenderView()<br />
    {<br />
        var render = new RenderCall&lt;ViewContext&gt;();<br />
        ViewEngine.Expect(v =&gt; v.RenderView(It.IsAny&lt;ViewContext&gt;()))<br />
            .Callback(new Action&lt;ViewContext&gt;(render.Set));<br />
        return render;<br />
    }<br />
}</font>
        </p>
        <p>
The RenderCall class provides a place to receive the view context that is passed. 
</p>
        <p>
public class RenderCall&lt;T&gt;<br />
{<br />
    bool _called;<br />
    T _data; 
</p>
        <p>
    public T Data<br />
    {<br />
        get<br />
        {<br />
            if (!_called) throw
new InvalidOperationException("View was not rendered.");<br />
            return _data;<br />
        }<br />
    } 
</p>
        <p>
    public void Set(T data)<br />
    {<br />
        _data = data;<br />
        _called = true;<br />
    }<br />
} <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=6c1cb700-c584-43b3-9fb2-7ee0fe1ae3cd" /></p>
      </body>
      <title>Testing Controller RenderView</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,6c1cb700-c584-43b3-9fb2-7ee0fe1ae3cd.aspx</guid>
      <link>http://www.aboutcode.net/2008/03/24/TestingControllerRenderView.aspx</link>
      <pubDate>Mon, 24 Mar 2008 16:08:16 GMT</pubDate>
      <description>&lt;p&gt;
I've seen people testing that RenderView is called by a controller by inheriting into
a "testable" controller. Madness!
&lt;/p&gt;
&lt;p&gt;
RenderView is just a convenience method that calls to IViewEngine, so why not just
test expectations on that with a mock? We basically want to test that the correct
ViewContext is sent to the RenderView method of the view engine.
&lt;/p&gt;
&lt;p&gt;
This is my test:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;[TestFixture]&lt;br&gt;
public class HomeControllerTests : ControllerTestsBase&amp;lt;HomeController&amp;gt;&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public override HomeController CreateController()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new HomeController();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Test]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public void Renders_Index()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var render = ExpectRenderView(); &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Controller.Index(); &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(render.Data.ViewName,
Is.EqualTo("Index"));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;/font&gt; 
&lt;p&gt;
I don't think we can get more straight forward than that!
&lt;/p&gt;
&lt;p&gt;
This is my test base class:&lt;br&gt;
(I'm using Moq as the mock framework.)
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;public abstract class ControllerTestsBase&amp;lt;T&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; where T : Controller&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public T Controller;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public Mock&amp;lt;IViewEngine&amp;gt; ViewEngine; &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [SetUp]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public virtual void SetUp()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Controller = CreateController();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ViewEngine = new Mock&amp;lt;IViewEngine&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Controller.ViewEngine = ViewEngine.Object; &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Controller.ControllerContext
= new Mock&amp;lt;ControllerContext&amp;gt;(new Mock&amp;lt;HttpContextBase&amp;gt;().Object, new
RouteData(), Controller).Object;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public abstract T CreateController(); &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public RenderCall&amp;lt;ViewContext&amp;gt; ExpectRenderView()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var render = new RenderCall&amp;lt;ViewContext&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ViewEngine.Expect(v =&amp;gt; v.RenderView(It.IsAny&amp;lt;ViewContext&amp;gt;()))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Callback(new Action&amp;lt;ViewContext&amp;gt;(render.Set));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return render;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;/font&gt; 
&lt;p&gt;
The RenderCall class provides a place to receive the view context that is passed. 
&lt;p&gt;
public class RenderCall&amp;lt;T&amp;gt;&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; bool _called;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; T _data; 
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public T Data&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!_called) throw
new InvalidOperationException("View was not rendered.");&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return _data;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public void Set(T data)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _data = data;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _called = true;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
} &lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=6c1cb700-c584-43b3-9fb2-7ee0fe1ae3cd" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,6c1cb700-c584-43b3-9fb2-7ee0fe1ae3cd.aspx</comments>
      <category>.net</category>
      <category>mvc</category>
      <category>thinking</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=4e588971-16cd-4e75-b64e-cefaf759ff66</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,4e588971-16cd-4e75-b64e-cefaf759ff66.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,4e588971-16cd-4e75-b64e-cefaf759ff66.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=4e588971-16cd-4e75-b64e-cefaf759ff66</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
VB.NET 9 introduces a clean syntax for expressing XML data. XHTML is XML so why not
use VB.NET to generate it, instead of ASPX pages? People are creating view engines
for the new ASP.NET MVC framework. How about a view engine that uses VB.NET XML literals?
</p>
        <p>
The benefits to this approach include full intellisense and access to a the full VB.NET
language when creating HTML.
</p>
        <p>
I see a view as a function from some data to an XML element (the &lt;html&gt; element):
</p>
        <p>
          <font face="Courier New">Function CustomersPage(ByVal title As String, ByVal customers
As IEnumerable(Of Customer)) As XElement<br />
    Return _<br />
        &lt;html&gt;<br />
            &lt;head&gt;<br />
               
&lt;title&gt;&lt;%= title %&gt;&lt;/title&gt;<br />
            &lt;/head&gt;<br />
            &lt;body&gt;<br />
            &lt;%= From customer
In customers Select _<br />
               
&lt;div id=&lt;%= customer.LastName %&gt;&gt;<br />
                   
&lt;h1&gt;&lt;%= customer.FirstName %&gt;&lt;/h1&gt;<br />
               
&lt;/div&gt; %&gt;<br />
            &lt;/body&gt;<br />
        &lt;/html&gt;<br />
End Function</font>
        </p>
        <p>
The important change from ASPX is that this is HTML in Code, rather than Code in HTML.
As a result less "automagical" behaviour is required; It's just a function! This means
AJAX features like "partial rendering", where a section of page needs to be updated,
can be expressed by just calling a function that returns a &lt;div&gt; element. That
same function can be used by the full HTML page function too.
</p>
        <p>
ASPX "usercontrols" become simply functions as well. ASPX Master Pages are functions
that have arguments for "placeholders" that get inserted into an template HTML page.
Instead of having to reinvent a bunch of programming language concepts inside ASPX,
we can just use a programming language that now support XML!
</p>
        <p>
The only down side to this approach is we lose the IDE visual designer support. However,
I find viewing an ASPX page that contains even simple conditional data rendering next
to useless. I'd rather keep IE open and just refresh the page to see changes.
</p>
        <p>
I am yet to embrace the MVC framework. I am waiting to see if the next release can
better support Snooze framework ideas. However, there's no reason I can't use this
VB XML magic in Snooze as it current is.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=4e588971-16cd-4e75-b64e-cefaf759ff66" />
      </body>
      <title>VB.NET 9 as an HTML View Engine</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,4e588971-16cd-4e75-b64e-cefaf759ff66.aspx</guid>
      <link>http://www.aboutcode.net/2008/02/19/VBNET9AsAnHTMLViewEngine.aspx</link>
      <pubDate>Tue, 19 Feb 2008 12:12:17 GMT</pubDate>
      <description>&lt;p&gt;
VB.NET 9 introduces a clean syntax for expressing XML data. XHTML is XML so why not
use VB.NET to generate it, instead of ASPX pages? People are creating view engines
for the new ASP.NET MVC framework. How about a view engine that uses VB.NET XML literals?
&lt;/p&gt;
&lt;p&gt;
The benefits to this approach include full intellisense and access to a the full VB.NET
language when creating HTML.
&lt;/p&gt;
&lt;p&gt;
I see a view as a function from some data to an XML element (the &amp;lt;html&amp;gt; element):
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;Function CustomersPage(ByVal title As String, ByVal customers
As IEnumerable(Of Customer)) As XElement&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Return _&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;html&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;head&amp;gt;&lt;br&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;lt;title&amp;gt;&amp;lt;%= title %&amp;gt;&amp;lt;/title&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/head&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;body&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;%= From customer
In customers Select _&lt;br&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;lt;div id=&amp;lt;%= customer.LastName %&amp;gt;&amp;gt;&lt;br&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;
&amp;lt;h1&amp;gt;&amp;lt;%= customer.FirstName %&amp;gt;&amp;lt;/h1&amp;gt;&lt;br&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;lt;/div&amp;gt; %&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/body&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/html&amp;gt;&lt;br&gt;
End Function&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The important change from ASPX is that this is HTML in Code, rather than Code in HTML.
As a result less "automagical" behaviour is required; It's just a function! This means
AJAX features like "partial rendering", where a section of page needs to be updated,
can be expressed by just calling a function that returns a &amp;lt;div&amp;gt; element. That
same function can be used by the full HTML page function too.
&lt;/p&gt;
&lt;p&gt;
ASPX "usercontrols" become simply functions as well. ASPX Master Pages are functions
that have arguments for "placeholders" that get inserted into an template HTML page.
Instead of having to reinvent a bunch of programming language concepts inside ASPX,
we can just use a programming language that now support XML!
&lt;/p&gt;
&lt;p&gt;
The only down side to this approach is we lose the IDE visual designer support. However,
I find viewing an ASPX page that contains even simple conditional data rendering next
to useless. I'd rather keep IE open and just refresh the page to see changes.
&lt;/p&gt;
&lt;p&gt;
I am yet to embrace the MVC framework. I am waiting to see if the next release can
better support Snooze framework ideas. However, there's no reason I can't use this
VB XML magic in Snooze as it current is.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=4e588971-16cd-4e75-b64e-cefaf759ff66" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,4e588971-16cd-4e75-b64e-cefaf759ff66.aspx</comments>
      <category>.net</category>
      <category>html</category>
      <category>thinking</category>
      <category>vb.net</category>
      <category>web</category>
      <category>xml</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=afe1d0c6-a4e5-451a-ad11-403a1e2126e4</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,afe1d0c6-a4e5-451a-ad11-403a1e2126e4.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,afe1d0c6-a4e5-451a-ad11-403a1e2126e4.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=afe1d0c6-a4e5-451a-ad11-403a1e2126e4</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have released an initial version of Snooze. <a title="http://www.assembla.com/wiki/show/snooze" href="http://www.assembla.com/wiki/show/snooze">http://www.assembla.com/wiki/show/snooze</a></p>
        <p>
Snooze is an REST framework for ASP.NET. It puts the emphasis back on the "R" of URI.
The Resource concept is a first-class citizen.
</p>
        <p>
In Snooze you create a resource class that defines the URI template and HTTP methods
it supports.
</p>
        <p>
          <font face="Courier New">[HttpResource("customer/{CustomerId}")] // Defines the URI
template for this resource<br />
public class CustomerResource : HttpResource // A useful base class that implements
IHttpResource<br />
{<br />
    // URI template variables are mapped to properties 
<br />
    public int CustomerId { get; set; }<br /><br />
    // Handles the HTTP GET method<br />
    public override void Get()<br />
    {<br /></font>
          <font face="Courier New">        RenderView("Customer",
Data.Customers[CustomerId]);<br />
    }<br /><br />
    public override void Put()<br />
    {<br /></font>
          <font face="Courier New">        // Read
data sent in Request body and update the customer...<br />
    }<br /></font>
          <font face="Courier New">
            <br />
    public override void Delete()<br />
    {<br />
        // Delete the customer...<br />
    }<br /><br />
    // HTTP POST can also be provided if it makes sense for the resource.<br />
}</font>
        </p>
        <p>
This will mean a URI like "http://yourserver.com/customer/42" will invoke the Get
method of an instance where CustomerId equals 42.
</p>
        <p>
What about creating a new Customer?
</p>
        <p>
Well you don't have an ID for the new customer since that is probably created in the
database. Therefore you don't know what the URI will be yet. The correct solution
here is to POST the new customer data to a CustomerList resource, with URI "/customers".
</p>
        <h2>Alternative GET Views
</h2>
        <p>
You can create extra GET methods:
</p>
        <p>
          <font face="Courier New">[HttpGetView("edit")]<br />
public void GetEdit()<br />
{<br />
    RenderView("CustomerEdit", Data.Customers[CustomerId]);<br />
}</font>
        </p>
        <p>
This results in URIs like "/customer/42?edit"
</p>
        <h2>File Extensions
</h2>
        <p>
To support different file formats, such as XML and JSON use:
</p>
        <font face="Courier New">[HttpGetFile(".xml")]<br />
public void GetEdit()<br />
{<br />
    SendXml(Data.Customers[CustomerId]);<br />
}</font>
        <p>
This will be mapped to by URIs like /customer/42.xml
</p>
        <h2>Sub-Resources
</h2>
        <p>
Resources can be naturally nested. For example, a Customer may have Orders.
</p>
        <p>
[HttpSubResource(typeof(CustomerResource), "order/{OrderId}", true)]<br />
public class OrderResource : HttpSubResource&lt;CustomerResource&gt;<br />
{<br />
    public int OrderId { get; set; }<br />
    // ... 
<br />
} 
</p>
        <p>
In this sub-resource, you can have access the parent CustomerResource, using the strongly-typed,
ParentResource property. 
</p>
        <p>
URIs for this sub-resource will look like: "/customer/42/order/123" 
</p>
        <p>
The "true" argument in the attribute, specifies that parent query string parameters
are added to this sub-resource URI as well. So a parent with URI template "customer/{CustomerId}?foo={Foo}"
will yield sub-resource URI template "/customer/{CustomerId}/order/{OrderId}?foo={Foo}". 
</p>
        <h2>Nullable Resource Properties
</h2>
        <p>
Imagine a blog posts resource. Its URI could be /posts/{Year}/{Month}/{Day} to get
all the posts on a given date. Now what if you want to naturally get the posts for
a whole month, year, or ever?
</p>
        <p>
By declaring the properties as nullable, e.g. "int?" in C#, Snooze will also map the
"reduced" URIs to your class. You can then test the properties for "null" and return
data accordingly.
</p>
        <h2>Reusing Resource URIs
</h2>
        <p>
When rendering an HTML view it is likely you will need to link to other resources.
Instead of manually typing the URI string, you can call the Uri property available
on HttpResource.
</p>
        <p>
          <font face="Courier New">new CustomerResource { CustomerId = 42 } .Uri</font>
        </p>
        <h2>Resource Areas
</h2>
        <p>
Snooze supports resource "areas". These let you map all the resources of a given assembly
into a given sub-path. If, for example, a third-party blogging package was built using
Snooze you could include it as follows:
</p>
        <p>
web.config:
</p>
        <p>
          <font face="Courier New">&lt;configuration&gt;<br />
  &lt;restAreas&gt;<br />
    &lt;area path="" assembly="MyWebsiteAssembly"/&gt;<br />
    &lt;area path="blog" assembly="SomeCompany.BlogEngine, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null"/&gt;<br />
  &lt;/restAreas&gt;</font>
        </p>
        <p>
So the blog resource URIs would look something like: <a href="http://mysite.com/blog/posts/2007/01">http://mysite.com/blog/posts/2007/01</a></p>
        <h2>HTML Form Support
</h2>
        <p>
HTML forms only support GET and POST. To overcome this limitation you can include:
&lt;input type="hidden" name="__method" value="DELETE" /&gt; to override the name
of the HTTP method used by Snooze.
</p>
        <h2>Feedback
</h2>
        <p>
This project came mostly out of curiosity! I wanted to see if REST could be done better
under ASP.NET. The code is still very new (less than two days!) It is open source
(BSD license) and available via <a href="http://svn2.assembla.com/svn/snooze/trunk">SubVersion</a>.
A quick sample project is also provided.
</p>
        <p>
Let me know what you think. Everything is open to changes. Join the <a href="http://www.assembla.com/wiki/show/snooze">assembla</a> project
if you would like to contribute your help.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=afe1d0c6-a4e5-451a-ad11-403a1e2126e4" />
      </body>
      <title>Snooze - A REST Framework for .NET</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,afe1d0c6-a4e5-451a-ad11-403a1e2126e4.aspx</guid>
      <link>http://www.aboutcode.net/2008/01/10/SnoozeARESTFrameworkForNET.aspx</link>
      <pubDate>Thu, 10 Jan 2008 21:42:04 GMT</pubDate>
      <description>&lt;p&gt;
I have released an initial version of Snooze. &lt;a title="http://www.assembla.com/wiki/show/snooze" href="http://www.assembla.com/wiki/show/snooze"&gt;http://www.assembla.com/wiki/show/snooze&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Snooze is an REST framework for ASP.NET. It puts the emphasis back on the "R" of URI.
The Resource concept is a first-class citizen.
&lt;/p&gt;
&lt;p&gt;
In Snooze you create a resource class that defines the URI template and HTTP methods
it supports.
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;[HttpResource("customer/{CustomerId}")] // Defines the URI
template for this resource&lt;br&gt;
public class CustomerResource : HttpResource // A useful base class that implements
IHttpResource&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // URI template variables are mapped to properties 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public int CustomerId { get; set; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Handles the HTTP GET method&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void Get()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RenderView("Customer",
Data.Customers[CustomerId]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void Put()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Read
data sent in Request body and update the customer...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;/font&gt;&lt;font face="Courier New"&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void Delete()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Delete the customer...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // HTTP POST can also be provided if it makes sense for the resource.&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
This will mean a URI like "http://yourserver.com/customer/42" will invoke the Get
method of an instance where CustomerId equals 42.
&lt;/p&gt;
&lt;p&gt;
What about creating a new Customer?
&lt;/p&gt;
&lt;p&gt;
Well you don't have an ID for the new customer since that is probably created in the
database. Therefore you don't know what the URI will be yet. The correct solution
here is to POST the new customer data to a CustomerList resource, with URI "/customers".
&lt;/p&gt;
&lt;h2&gt;Alternative GET Views
&lt;/h2&gt;
&lt;p&gt;
You can create extra GET methods:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;[HttpGetView("edit")]&lt;br&gt;
public void GetEdit()&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RenderView("CustomerEdit", Data.Customers[CustomerId]);&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
This results in URIs like "/customer/42?edit"
&lt;/p&gt;
&lt;h2&gt;File Extensions
&lt;/h2&gt;
&lt;p&gt;
To support different file formats, such as XML and JSON use:
&lt;/p&gt;
&lt;font face="Courier New"&gt;[HttpGetFile(".xml")]&lt;br&gt;
public void GetEdit()&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; SendXml(Data.Customers[CustomerId]);&lt;br&gt;
}&lt;/font&gt; 
&lt;p&gt;
This will be mapped to by URIs like /customer/42.xml
&lt;/p&gt;
&lt;h2&gt;Sub-Resources
&lt;/h2&gt;
&lt;p&gt;
Resources can be naturally nested. For example, a Customer may have Orders.
&lt;/p&gt;
&lt;p&gt;
[HttpSubResource(typeof(CustomerResource), "order/{OrderId}", true)]&lt;br&gt;
public class OrderResource : HttpSubResource&amp;lt;CustomerResource&amp;gt;&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public int OrderId { get; set; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // ... 
&lt;br&gt;
} 
&lt;p&gt;
In this sub-resource, you can have access the parent CustomerResource, using the strongly-typed,
ParentResource property. 
&lt;p&gt;
URIs for this sub-resource will look like: "/customer/42/order/123" 
&lt;p&gt;
The "true" argument in the attribute, specifies that parent query string parameters
are added to this sub-resource URI as well. So a parent with URI template "customer/{CustomerId}?foo={Foo}"
will yield sub-resource URI template "/customer/{CustomerId}/order/{OrderId}?foo={Foo}". 
&lt;h2&gt;Nullable Resource Properties
&lt;/h2&gt;
&lt;p&gt;
Imagine a blog posts resource. Its URI could be /posts/{Year}/{Month}/{Day} to get
all the posts on a given date. Now what if you want to naturally get the posts for
a whole month, year, or ever?
&lt;/p&gt;
&lt;p&gt;
By declaring the properties as nullable, e.g. "int?" in C#, Snooze will also map the
"reduced" URIs to your class. You can then test the properties for "null" and return
data accordingly.
&lt;/p&gt;
&lt;h2&gt;Reusing Resource URIs
&lt;/h2&gt;
&lt;p&gt;
When rendering an HTML view it is likely you will need to link to other resources.
Instead of manually typing the URI string, you can call the Uri property available
on HttpResource.
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;new CustomerResource { CustomerId = 42 } .Uri&lt;/font&gt;
&lt;/p&gt;
&lt;h2&gt;Resource Areas
&lt;/h2&gt;
&lt;p&gt;
Snooze supports resource "areas". These let you map all the resources of a given assembly
into a given sub-path. If, for example, a third-party blogging package was built using
Snooze you could include it as follows:
&lt;/p&gt;
&lt;p&gt;
web.config:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;lt;configuration&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;restAreas&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;area path="" assembly="MyWebsiteAssembly"/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;area path="blog" assembly="SomeCompany.BlogEngine, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null"/&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;/restAreas&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
So the blog resource URIs would look something like: &lt;a href="http://mysite.com/blog/posts/2007/01"&gt;http://mysite.com/blog/posts/2007/01&lt;/a&gt;
&lt;/p&gt;
&lt;h2&gt;HTML Form Support
&lt;/h2&gt;
&lt;p&gt;
HTML forms only support GET and POST. To overcome this limitation you can include:
&amp;lt;input type="hidden" name="__method" value="DELETE" /&amp;gt; to override the name
of the HTTP method used by Snooze.
&lt;/p&gt;
&lt;h2&gt;Feedback
&lt;/h2&gt;
&lt;p&gt;
This project came mostly out of curiosity! I wanted to see if REST could be done better
under ASP.NET. The code is still very new (less than two days!) It is open source
(BSD license) and available via &lt;a href="http://svn2.assembla.com/svn/snooze/trunk"&gt;SubVersion&lt;/a&gt;.
A quick sample project is also provided.
&lt;/p&gt;
&lt;p&gt;
Let me know what you think. Everything is open to changes. Join the &lt;a href="http://www.assembla.com/wiki/show/snooze"&gt;assembla&lt;/a&gt; project
if you would like to contribute your help.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=afe1d0c6-a4e5-451a-ad11-403a1e2126e4" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,afe1d0c6-a4e5-451a-ad11-403a1e2126e4.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>programming</category>
      <category>REST</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=bcbf7b31-8654-4278-9e79-f116d3fc62f1</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,bcbf7b31-8654-4278-9e79-f116d3fc62f1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,bcbf7b31-8654-4278-9e79-f116d3fc62f1.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=bcbf7b31-8654-4278-9e79-f116d3fc62f1</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am yet to play with the new ASP.NET MVC framework. However, I am spending time reading
around the area to see if it will benefit me to get more involved.
</p>
        <p>
A concern that came to mind when researching is the claims of it enabling a RESTful
approach to web programming. Whilst this may be true, all the examples so far seem
contrary to REST. My limited understanding of REST says that URLs represent a <strong>R</strong>esource.
How is <a href="http://www.mysite.com/customers/delete/42">http://www.mysite.com/customers/delete/42</a> a
resource?!
</p>
        <p>
Yet that is indeed the format of URL we are being shown by Scott Guthrie and others.
It makes ASP.NET MVC look more like another RPC system, just with parameters encoded
into the address instead of message body.
</p>
        <p>
So is it possible to specify a resource URL and then a number of HTTP verbs that can
execute against it? It probably is, given the extensibility of ASP.NET MVC's architecture.
However, one may ask, should I be hacking this into the framework? Would the end result
look anything like the original MVC code at all? Probably not!
</p>
        <p>
          <strong>Is it time for a real REST framework built on top of ASP.NET? I think it is!</strong>
        </p>
        <p>
It needs to be Resource centered. It needs to fully leverage the rich feature set
of HTTP, not just GET and POST! And just to be awesome, it needs to have a client-side
story too. Real REST relies on the client-side to store state. Could this be Silverlight,
or do we still want JavaScript? (I'm up for cross compiling to JS from C# or MSIL!)
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=bcbf7b31-8654-4278-9e79-f116d3fc62f1" />
      </body>
      <title>REST Verbs in ASP.NET MVC</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,bcbf7b31-8654-4278-9e79-f116d3fc62f1.aspx</guid>
      <link>http://www.aboutcode.net/2007/12/23/RESTVerbsInASPNETMVC.aspx</link>
      <pubDate>Sun, 23 Dec 2007 16:02:00 GMT</pubDate>
      <description>&lt;p&gt;
I am yet to play with the new ASP.NET MVC framework. However, I am spending time reading
around the area to see if it will benefit me to get more involved.
&lt;/p&gt;
&lt;p&gt;
A concern that came to mind when researching is the claims of it enabling a RESTful
approach to web programming. Whilst this may be true, all the examples so far seem
contrary to REST. My limited understanding of REST says that URLs represent a &lt;strong&gt;R&lt;/strong&gt;esource.
How is &lt;a href="http://www.mysite.com/customers/delete/42"&gt;http://www.mysite.com/customers/delete/42&lt;/a&gt; a
resource?!
&lt;/p&gt;
&lt;p&gt;
Yet that is indeed the format of URL we are being shown by Scott Guthrie and others.
It makes ASP.NET MVC look more like another RPC system, just with parameters encoded
into the address instead of message body.
&lt;/p&gt;
&lt;p&gt;
So is it possible to specify a resource URL and then a number of HTTP verbs that can
execute against it? It probably is, given the extensibility of ASP.NET MVC's architecture.
However, one may ask, should I be hacking this into the framework? Would the end result
look anything like the original MVC code at all? Probably not!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Is it time for a real REST framework built on top of ASP.NET? I think it is!&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
It needs to be Resource centered. It needs to fully leverage the rich feature set
of HTTP, not just GET and POST! And just to be awesome, it needs to have a client-side
story too. Real REST relies on the client-side to store state. Could this be Silverlight,
or do we still want JavaScript? (I'm up for cross compiling to JS from C# or MSIL!)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=bcbf7b31-8654-4278-9e79-f116d3fc62f1" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,bcbf7b31-8654-4278-9e79-f116d3fc62f1.aspx</comments>
      <category>.net</category>
      <category>programming</category>
      <category>REST</category>
      <category>ria</category>
      <category>thinking</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=ef59c8c0-9d08-47c7-9a09-bf70e0c28c9b</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,ef59c8c0-9d08-47c7-9a09-bf70e0c28c9b.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,ef59c8c0-9d08-47c7-9a09-bf70e0c28c9b.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ef59c8c0-9d08-47c7-9a09-bf70e0c28c9b</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've made a custom Visual Studio tool that uses a C# parser<br />
(<a href="http://www.codeplex.com/csparser/">http://www.codeplex.com/csparser/</a>)
to convert C# code into an XML<br />
representation. So far only the declaration stuff, classes, method<br />
signatures etc.<br />
I then have a XSLT template engine that takes the XML and a template<br />
file to generate content.<br />
Templates look like:<br />
&lt;% for-each /namespace/class[attribute/@type='ServerModel'] %&gt;<br />
public class &lt;%@name%&gt;<br />
{<br />
}<br />
&lt;%/for-each%&gt;<br />
Easy stuff if you are happy with XSLT.<br />
Currently I use it to generate proxies to classes in my Mobile MVP<br />
library. There are lots of uses I imagine.<br />
Are there any other similar tools out there? If not what are the<br />
prefered places to release this? I took a look at CodePlex but the<br />
TFS source control made me shudder. I'm much more at home with SVN...
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=ef59c8c0-9d08-47c7-9a09-bf70e0c28c9b" />
      </body>
      <title>C# Code Transformation Tool</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,ef59c8c0-9d08-47c7-9a09-bf70e0c28c9b.aspx</guid>
      <link>http://www.aboutcode.net/2007/11/04/CCodeTransformationTool.aspx</link>
      <pubDate>Sun, 04 Nov 2007 23:02:13 GMT</pubDate>
      <description>&lt;p&gt;
I've made a custom Visual Studio tool that uses a C# parser&lt;br&gt;
(&lt;a href="http://www.codeplex.com/csparser/"&gt;http://www.codeplex.com/csparser/&lt;/a&gt;)
to convert C# code into an XML&lt;br&gt;
representation. So far only the declaration stuff, classes, method&lt;br&gt;
signatures etc.&lt;br&gt;
I then have a XSLT template engine that takes the XML and a template&lt;br&gt;
file to generate content.&lt;br&gt;
Templates look like:&lt;br&gt;
&amp;lt;% for-each /namespace/class[attribute/@type='ServerModel'] %&amp;gt;&lt;br&gt;
public class &amp;lt;%@name%&amp;gt;&lt;br&gt;
{&lt;br&gt;
}&lt;br&gt;
&amp;lt;%/for-each%&amp;gt;&lt;br&gt;
Easy stuff if you are happy with XSLT.&lt;br&gt;
Currently I use it to generate proxies to classes in my Mobile MVP&lt;br&gt;
library. There are lots of uses I imagine.&lt;br&gt;
Are there any other similar tools out there? If not what are the&lt;br&gt;
prefered places to release this? I took a look at CodePlex but the&lt;br&gt;
TFS source control made me shudder. I'm much more at home with SVN...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=ef59c8c0-9d08-47c7-9a09-bf70e0c28c9b" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,ef59c8c0-9d08-47c7-9a09-bf70e0c28c9b.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>programming</category>
      <category>thinking</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=5965a970-eb7e-4282-b599-7a5a58777370</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,5965a970-eb7e-4282-b599-7a5a58777370.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,5965a970-eb7e-4282-b599-7a5a58777370.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=5965a970-eb7e-4282-b599-7a5a58777370</wfw:commentRss>
      <slash:comments>11</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
My latest screencast is online: <a title="Mobile Model in MVP web app" href="http://channel9.msdn.com/Showpost.aspx?postid=348722">Mobile
Model in MVP web app</a></p>
        <p>
This screencast continues from the work I demonstrated in a previous screencast: <a href="http://channel9.msdn.com/Showpost.aspx?postid=344711">http://channel9.msdn.com/Showpost.aspx?postid=344711</a><br />
When implemented a Model-View-Presenter pattern client-side in JavaScript there is
a need to get data from the server. Rather than make this divide explicit with HTTP
request, etc, I have used the idea of a model object that moves between the client
and server.<br />
So the programmer simply writes the client and server pieces of functionality and
lets my framework do the plumbing.<br />
I use code generation and <a href="http://projects.nikhilk.net/Projects/ScriptSharp.aspx">Script#</a> to
make writing a client-side web app much more seemless than the usual javascript/XML/JSON/web
service madness.<br />
I'm developing the ideas shown here in a project at the moment. If there is sufficient
interest I may extract a framework to give to the community.<br />
How do people feel about this approach to web development? What kinds of additions/modifications
should be made?<br />
p.s. I have a bit of a cold at the moment, so sorry for the croaky voice in the recording!
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=5965a970-eb7e-4282-b599-7a5a58777370" />
      </body>
      <title>Mobile Model Screencast</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,5965a970-eb7e-4282-b599-7a5a58777370.aspx</guid>
      <link>http://www.aboutcode.net/2007/10/17/MobileModelScreencast.aspx</link>
      <pubDate>Wed, 17 Oct 2007 20:32:19 GMT</pubDate>
      <description>&lt;p&gt;
My latest screencast is online: &lt;a title="Mobile Model in MVP web app" href="http://channel9.msdn.com/Showpost.aspx?postid=348722"&gt;Mobile
Model in MVP web app&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
This screencast continues from the work I demonstrated in a previous screencast: &lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=344711"&gt;http://channel9.msdn.com/Showpost.aspx?postid=344711&lt;/a&gt;
&lt;br&gt;
When implemented a Model-View-Presenter pattern client-side in JavaScript there is
a need to get data from the server. Rather than make this divide explicit with HTTP
request, etc, I have used the idea of a model object that moves between the client
and server.&lt;br&gt;
So the programmer simply writes the client and server pieces of functionality and
lets my framework do the plumbing.&lt;br&gt;
I use code generation and&amp;nbsp;&lt;a href="http://projects.nikhilk.net/Projects/ScriptSharp.aspx"&gt;Script#&lt;/a&gt; to
make writing a client-side web app much more seemless than the usual javascript/XML/JSON/web
service&amp;nbsp;madness.&lt;br&gt;
I'm developing the ideas shown here in a project at the moment. If there is sufficient
interest I may extract a framework to give to the community.&lt;br&gt;
How do people feel about this approach to web development? What kinds of additions/modifications
should be made?&lt;br&gt;
p.s. I have a bit of a cold at the moment, so sorry for the croaky voice in the recording!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=5965a970-eb7e-4282-b599-7a5a58777370" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,5965a970-eb7e-4282-b599-7a5a58777370.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>mvp</category>
      <category>programming</category>
      <category>ria</category>
      <category>screencast</category>
      <category>tier_split</category>
      <category>web</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=900db2c5-53ea-417f-a093-71dae4db5622</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,900db2c5-53ea-417f-a093-71dae4db5622.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,900db2c5-53ea-417f-a093-71dae4db5622.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=900db2c5-53ea-417f-a093-71dae4db5622</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Has anyone looked into an extension method on the .NET 3.5 Expression class that returns
a JavaScript method? This could then be sent to the client web browser.
</p>
        <p>
So you could then write validation logic in C# and run it in the browser as JavaScript!
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=900db2c5-53ea-417f-a093-71dae4db5622" />
      </body>
      <title>ToJavaScript Extension Method</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,900db2c5-53ea-417f-a093-71dae4db5622.aspx</guid>
      <link>http://www.aboutcode.net/2007/10/02/ToJavaScriptExtensionMethod.aspx</link>
      <pubDate>Tue, 02 Oct 2007 08:39:56 GMT</pubDate>
      <description>&lt;p&gt;
Has anyone looked into an extension method on the .NET 3.5 Expression class that returns
a JavaScript method? This could then be sent to the client web browser.
&lt;/p&gt;
&lt;p&gt;
So you could then write validation logic in C# and run it in the browser as JavaScript!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=900db2c5-53ea-417f-a093-71dae4db5622" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,900db2c5-53ea-417f-a093-71dae4db5622.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>linq</category>
      <category>thinking</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=9392a1d0-3150-4ddf-8d1b-6df797a4b6cf</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,9392a1d0-3150-4ddf-8d1b-6df797a4b6cf.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,9392a1d0-3150-4ddf-8d1b-6df797a4b6cf.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=9392a1d0-3150-4ddf-8d1b-6df797a4b6cf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am thinking about my client-side MVP pattern and how best to communicate with the
server. The current issue is how explicit to make the client/server divide. There
are ways to make it feel like the Model is one consistent class, with tools doing
all the marshalling to the server, invocation and return. This papering over of the
"cracks" may however bite me in the ass at a later date. I reckon that adding the
required flexibility to enable tweaking will just end up making the divide explicit
again - rendering the exercise pointless.
</p>
        <p>
So the alternative is to write the model with only client-side code. The server-side
logic will then be in a service class somewhere. A benefit here is that the developer
is free to choose the service style (SOAP, REST, etc).
</p>
        <p>
I still want to avoid writing the client-side model proxy class that calls to the
server. A tool is needed to take a service description and create a proxy class. In
the context of a JavaScript model object, we need the proxy to be making XML
HTTP requests.
</p>
        <p>
I would like to use WCF to create the service. <a href="http://blogs.msdn.com/kaevans/archive/2007/09/04/using-wcf-json-linq-and-ajax-passing-complex-types-to-wcf-services-with-json-encoding.aspx">This</a> is
a good overview of getting WCF to talk JSON. If I enable meta-data transfer on the
service, writing a tool to read this and create a proxy class should be simple.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=9392a1d0-3150-4ddf-8d1b-6df797a4b6cf" />
      </body>
      <title>Thoughts on client-server communication for the Model in MVP</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,9392a1d0-3150-4ddf-8d1b-6df797a4b6cf.aspx</guid>
      <link>http://www.aboutcode.net/2007/09/30/ThoughtsOnClientserverCommunicationForTheModelInMVP.aspx</link>
      <pubDate>Sun, 30 Sep 2007 09:02:14 GMT</pubDate>
      <description>&lt;p&gt;
I am thinking about my client-side MVP pattern and how best to communicate with the
server. The current issue is how&amp;nbsp;explicit to make the client/server divide. There
are ways to make it feel like the Model is one consistent class, with tools doing
all the marshalling to the server, invocation and return. This papering over of the
"cracks" may however bite me in the ass at a later date. I reckon that adding the
required flexibility to enable tweaking will just end up making the divide explicit
again - rendering the exercise pointless.
&lt;/p&gt;
&lt;p&gt;
So the alternative is to write the model&amp;nbsp;with only client-side code. The server-side
logic will then be in a service class somewhere. A benefit here is that the developer
is free to choose the service style (SOAP, REST, etc).
&lt;/p&gt;
&lt;p&gt;
I still want to avoid writing the client-side model proxy class that calls to the
server. A tool is needed to take a service description and create a proxy class. In
the context of a JavaScript model&amp;nbsp;object, we need the proxy to be making XML
HTTP requests.
&lt;/p&gt;
&lt;p&gt;
I would like to use WCF to create the service. &lt;a href="http://blogs.msdn.com/kaevans/archive/2007/09/04/using-wcf-json-linq-and-ajax-passing-complex-types-to-wcf-services-with-json-encoding.aspx"&gt;This&lt;/a&gt; is
a good overview of getting WCF to talk JSON. If I enable meta-data transfer on the
service, writing a tool to read this and create a proxy class should be simple.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=9392a1d0-3150-4ddf-8d1b-6df797a4b6cf" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,9392a1d0-3150-4ddf-8d1b-6df797a4b6cf.aspx</comments>
      <category>.net</category>
      <category>mvp</category>
      <category>thinking</category>
      <category>tier_split</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=b3c24e16-a240-4eb4-b6cd-a5e420613f33</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,b3c24e16-a240-4eb4-b6cd-a5e420613f33.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,b3c24e16-a240-4eb4-b6cd-a5e420613f33.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=b3c24e16-a240-4eb4-b6cd-a5e420613f33</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Check out my latest <a href="http://channel9.msdn.com/Showpost.aspx?postid=344711" target="_blank">screencast</a> over
at Channel 9. It demonstrates how to implement a model-view-presenter architecture
that runs client-side in a web browser. I am using <a href="http://projects.nikhilk.net/Projects/ScriptSharp.aspx">Script#</a> to
compile a C# project into JavaScript.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=b3c24e16-a240-4eb4-b6cd-a5e420613f33" />
      </body>
      <title>Client-side MVP Screencast</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,b3c24e16-a240-4eb4-b6cd-a5e420613f33.aspx</guid>
      <link>http://www.aboutcode.net/2007/09/29/ClientsideMVPScreencast.aspx</link>
      <pubDate>Sat, 29 Sep 2007 16:08:52 GMT</pubDate>
      <description>&lt;p&gt;
Check out my latest &lt;a href="http://channel9.msdn.com/Showpost.aspx?postid=344711" target="_blank"&gt;screencast&lt;/a&gt; over
at Channel 9. It demonstrates how to implement a model-view-presenter architecture
that runs client-side in a web browser. I am using &lt;a href="http://projects.nikhilk.net/Projects/ScriptSharp.aspx"&gt;Script#&lt;/a&gt; to
compile a C# project into JavaScript.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=b3c24e16-a240-4eb4-b6cd-a5e420613f33" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,b3c24e16-a240-4eb4-b6cd-a5e420613f33.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>mvp</category>
      <category>programming</category>
      <category>screencast</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=e0c4d054-0e59-4ba1-8fd4-80e7467e0816</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,e0c4d054-0e59-4ba1-8fd4-80e7467e0816.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,e0c4d054-0e59-4ba1-8fd4-80e7467e0816.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=e0c4d054-0e59-4ba1-8fd4-80e7467e0816</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Imagine we have a set of complex expressions. A subset of these need to be evaluated
at runtime, depending on some state external to the program (e.g. user input). If
these subsets are not distinct from each other then the code will likely become messy
and unstructured.
</p>
        <p>
What we would like to so is define all the expressions first and then pick and choose
those required. This would of course involve evaluating all of the them. This wasteful
of time if only a few are required.
</p>
        <p>
Enter lazy evaluation! From my rather limited exposure to Haskell, I hear that lazy
evaluation is all the rage. :)
</p>
        <p>
Using lambdas in C# 3.0 we can create code like this:
</p>
        <p>
long x = 42;<br />
var lx = Lazy.Eval(() =&gt; x * x * x * x * x * x);<br />
if (some_boolean_expression)<br />
{<br />
  UseNumber(lx);<br />
}
</p>
        <p>
where UseNumber is some function that takes a "long" as input.
</p>
        <p>
Now this example is over-simplified, but it shows the mechanics. We use a call to
Lazy.Eval to return a wrapper around the lambda. So at that point we have not calculated
the expensive expression. Later in the program the variable "lx" is used. lx is of
type <font face="Courier New">Lazy&lt;long&gt;</font> and there exists an implicit
cast from <font face="Courier New">Lazy&lt;long&gt;</font> to <font face="Courier New">long</font>.
At this point the original expression is evaluated and saved by the lazy wrapper.
So next time the value is required the cached value is returned.
</p>
        <p>
Here is the Lazy&lt;T&gt; class:
</p>
        <p>
          <font face="Courier New">public class Lazy&lt;T&gt;<br />
{       
<br />
    bool _gotValue;<br />
    T _value;<br />
    Func&lt;T&gt; _expr; </font>
        </p>
        <p>
          <font face="Courier New">    public Lazy(Func&lt;T&gt; expr)<br />
    {<br />
        _expr = expr;<br />
    } </font>
        </p>
        <p>
          <font face="Courier New">    public T Value<br />
    {<br />
        get<br />
        {<br />
            if (!_gotValue)<br />
            {<br />
               
_value = _expr();<br />
               
_gotValue = true;<br />
            }<br />
            return _value;<br />
        }<br />
    } </font>
        </p>
        <p>
          <font face="Courier New">    public static implicit operator T(Lazy&lt;T&gt;
l)<br />
    {<br />
        return l.Value;<br />
    }<br />
}</font>
        </p>
        <p>
          <font face="tre">And to allow the C# 3.0 compiler to infer types for us, we use a
separate Lazy class:</font>
        </p>
        <p>
          <font face="Courier New">public class Lazy<br />
{ 
<br />
    public static Lazy&lt;T&gt; Eval&lt;T&gt;(Func&lt;T&gt; expr)<br />
    {<br />
        return new Lazy&lt;T&gt;(expr);<br />
    }<br />
}</font>
        </p>
        <p>
          <font face="tr">Whilst lazy evaluation may not be useful in everyday programming,
this example does show some of what can be achieved with lambdas in C# 3.0.</font>
        </p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=e0c4d054-0e59-4ba1-8fd4-80e7467e0816" />
      </body>
      <title>Lazy Functions in LINQ</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,e0c4d054-0e59-4ba1-8fd4-80e7467e0816.aspx</guid>
      <link>http://www.aboutcode.net/2007/09/27/LazyFunctionsInLINQ.aspx</link>
      <pubDate>Thu, 27 Sep 2007 10:56:51 GMT</pubDate>
      <description>&lt;p&gt;
Imagine we have a set of complex expressions. A subset of these need to be evaluated
at runtime, depending on some state external to the program (e.g. user input). If
these subsets are not distinct from each other then the code will likely become messy
and unstructured.
&lt;/p&gt;
&lt;p&gt;
What we would like to so is define all the expressions first and then pick and choose
those required. This would of course involve evaluating all of the them. This wasteful
of time if only a few are required.
&lt;/p&gt;
&lt;p&gt;
Enter lazy evaluation! From my rather limited exposure to Haskell, I hear that lazy
evaluation is all the rage. :)
&lt;/p&gt;
&lt;p&gt;
Using lambdas in C# 3.0 we can create code like this:
&lt;/p&gt;
&lt;p&gt;
long x = 42;&lt;br&gt;
var lx = Lazy.Eval(() =&amp;gt; x * x * x * x * x * x);&lt;br&gt;
if (some_boolean_expression)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp; UseNumber(lx);&lt;br&gt;
}
&lt;/p&gt;
&lt;p&gt;
where UseNumber is&amp;nbsp;some function that takes a "long" as input.
&lt;/p&gt;
&lt;p&gt;
Now this example is over-simplified, but it shows the mechanics. We use a call to
Lazy.Eval to return a wrapper around the lambda. So at that point we have not calculated
the expensive expression. Later in the program the variable "lx" is used. lx is of
type &lt;font face="Courier New"&gt;Lazy&amp;lt;long&amp;gt;&lt;/font&gt; and there exists&amp;nbsp;an implicit
cast from &lt;font face="Courier New"&gt;Lazy&amp;lt;long&amp;gt;&lt;/font&gt; to &lt;font face="Courier New"&gt;long&lt;/font&gt;.
At this point the original expression is evaluated and saved by the lazy wrapper.
So next time the value is required the cached value is returned.
&lt;/p&gt;
&lt;p&gt;
Here is the Lazy&amp;lt;T&amp;gt; class:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;public class Lazy&amp;lt;T&amp;gt;&lt;br&gt;
{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; bool _gotValue;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; T _value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Func&amp;lt;T&amp;gt; _expr; &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Lazy(Func&amp;lt;T&amp;gt; expr)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _expr = expr;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public T Value&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!_gotValue)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&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;
_value = _expr();&lt;br&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;
_gotValue = true;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return _value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static implicit operator T(Lazy&amp;lt;T&amp;gt;
l)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return l.Value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="tre"&gt;And to allow the C# 3.0 compiler to infer types for us, we use a
separate Lazy class:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;public class Lazy&lt;br&gt;
{ 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public static Lazy&amp;lt;T&amp;gt; Eval&amp;lt;T&amp;gt;(Func&amp;lt;T&amp;gt; expr)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new Lazy&amp;lt;T&amp;gt;(expr);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="tr"&gt;Whilst lazy evaluation may not be useful in everyday programming,
this example does show some of what can be achieved with lambdas in C# 3.0.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=e0c4d054-0e59-4ba1-8fd4-80e7467e0816" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,e0c4d054-0e59-4ba1-8fd4-80e7467e0816.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>linq</category>
      <category>programming</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=6ce406ff-3ed9-4792-b0a3-7f12bb067353</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,6ce406ff-3ed9-4792-b0a3-7f12bb067353.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,6ce406ff-3ed9-4792-b0a3-7f12bb067353.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6ce406ff-3ed9-4792-b0a3-7f12bb067353</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Have you seen <a href="http://www.nikhilk.net/ScriptSharpIntro.aspx">Script#</a>?
It is very impressive cross-compiler from C# to JavaScript. The libraries make it
simple to program against the HTML DOM and Silverlight among other technologies. I
have been using them recently to program Silverlight 1.0 without having to actually
touch JavaScript. Using high-level OOP concepts makes creating complex user interactions
much easier. 
</p>
        <p>
The Model-View-Presenter pattern has been very popular on the server-side when creating
HTML applications. However, it seems that not many people have considered using it
within the browser. With AJAX techniques becoming <strong>the</strong> way to make
interactive web applications, it seems a little odd that people are not using more
high-level concepts client-side. Of course, this mostly applies to the .NET space.
I am aware there are Java toolkits that generate JavaScript. 
</p>
        <p>
I am therefore going to look into using Script# to implement a client-side, MVP-style,
web application. The Model will contain local data and communicate with the server
(via XML HTTP requests). The View will be a simple object that can get and set values
from HTML/Silverlight elements and raise events when the user clicks on buttons, etc.
The Presenter object will then orchestrate the user interaction logic. All this will
be done within JavaScript by using Script# to convert C# classes, etc, into JavaScript
concepts. 
</p>
        <p>
By writing all the code C#, it should be possible to tier split the Model class into
server-side and client-side pieces. Whilst the JavaScript on the client-side is drastically
different from the C# server-side model, they will share a common set of data fields.
So it should be possible to serialize between the two worlds.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=6ce406ff-3ed9-4792-b0a3-7f12bb067353" />
      </body>
      <title>Client-side MVP with Script#</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,6ce406ff-3ed9-4792-b0a3-7f12bb067353.aspx</guid>
      <link>http://www.aboutcode.net/2007/09/17/ClientsideMVPWithScript.aspx</link>
      <pubDate>Mon, 17 Sep 2007 16:24:00 GMT</pubDate>
      <description>&lt;p&gt;
Have you seen &lt;a href="http://www.nikhilk.net/ScriptSharpIntro.aspx"&gt;Script#&lt;/a&gt;?
It is very impressive cross-compiler from C# to JavaScript. The libraries make it
simple to program against the HTML DOM and Silverlight among other technologies. I
have been using them recently to program Silverlight 1.0 without having to actually
touch JavaScript. Using high-level OOP concepts makes creating complex user interactions
much easier. 
&lt;/p&gt;
&lt;p&gt;
The Model-View-Presenter pattern has been very popular on the server-side when creating
HTML applications. However, it seems that not many people have considered using it
within the browser. With AJAX techniques becoming &lt;strong&gt;the&lt;/strong&gt; way to make
interactive web applications, it seems a little odd that people are not using more
high-level concepts client-side. Of course, this mostly applies to the .NET space.
I am aware there are Java toolkits that generate JavaScript. 
&lt;/p&gt;
&lt;p&gt;
I am therefore going to look into using Script# to implement a client-side, MVP-style,
web application. The Model will contain local data and communicate with the server
(via XML HTTP requests). The View will be a simple object that can get and set values
from HTML/Silverlight elements and raise events when the user clicks on buttons, etc.
The Presenter object will then orchestrate the user interaction logic. All this will
be done within JavaScript by using Script# to convert C# classes, etc, into JavaScript
concepts. 
&lt;/p&gt;
&lt;p&gt;
By writing all the code C#, it should be possible to tier split the Model class into
server-side and client-side pieces. Whilst the JavaScript on the client-side is drastically
different from the C# server-side model, they will share a common set of data fields.
So it should be possible to serialize between the two worlds.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=6ce406ff-3ed9-4792-b0a3-7f12bb067353" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,6ce406ff-3ed9-4792-b0a3-7f12bb067353.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>programming</category>
      <category>silverlight</category>
      <category>thinking</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=f5a854c2-f0d2-4f3b-8ba6-055e3546c816</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,f5a854c2-f0d2-4f3b-8ba6-055e3546c816.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,f5a854c2-f0d2-4f3b-8ba6-055e3546c816.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=f5a854c2-f0d2-4f3b-8ba6-055e3546c816</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When writing assertions it is annoying to write a string that basically mirrors
what the code your testing says. For example:
</p>
        <p>
Debug.Assert(input != null, "input != null");
</p>
        <p>
Similar statements appear when unit testing with tools like <a href="http://www.nunit.org/index.php?p=assertions&amp;r=2.2.7">NUnit</a>.
</p>
        <p>
With Linq it is now possible to avoid this by using expression trees. The basic idea
is to take a boolean assertion function as an expression tree so that we can call
ToString() to get the message for the assert.
</p>
        <p>
void Assert&lt;T&gt;(T obj, Expression&lt;Func&lt;T, bool&gt;&gt; test)<br />
{<br />
  System.Diagnostics.Debug.Assert(test.Compile().Invoke(obj), test.ToString());<br />
}
</p>
        <p>
This is then called like:
</p>
        <p>
Assert(input, i =&gt; i != null);
</p>
        <p>
Given this idea, we can play with the syntax a bit. Using an extension method:
</p>
        <p>
static class Exts<br />
{<br />
    public static void MustSatisfy&lt;T&gt;(this T obj, Expression&lt;Func&lt;T,
bool&gt;&gt; test)<br />
    {<br />
        Debug.Assert(test.Compile().Invoke(obj),
test.ToString());<br />
    }<br />
} 
</p>
        <p>
We then have: 
</p>
        <p>
input.MustSatisfy(i =&gt; i != null) 
</p>
        <p>
Another syntax option would be something like: 
</p>
        <p>
Assert.That(foo).Satisfies(<br />
  i =&gt; i &gt; 0,<br />
  i =&gt; i &lt; 100); 
</p>
        <p>
Where we are now passing an array of assertions (using a params arg in the Satisfies
method).
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=f5a854c2-f0d2-4f3b-8ba6-055e3546c816" />
      </body>
      <title>Assertions via Linq Expressions</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,f5a854c2-f0d2-4f3b-8ba6-055e3546c816.aspx</guid>
      <link>http://www.aboutcode.net/2007/09/05/AssertionsViaLinqExpressions.aspx</link>
      <pubDate>Wed, 05 Sep 2007 11:46:23 GMT</pubDate>
      <description>&lt;p&gt;
When writing assertions&amp;nbsp;it is annoying to write a string that basically mirrors
what the code your testing says. For example:
&lt;/p&gt;
&lt;p&gt;
Debug.Assert(input != null, "input != null");
&lt;/p&gt;
&lt;p&gt;
Similar statements appear when unit testing with tools like &lt;a href="http://www.nunit.org/index.php?p=assertions&amp;amp;r=2.2.7"&gt;NUnit&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
With Linq it is now possible to avoid this by using expression trees. The basic idea
is to take a boolean assertion function as an expression tree so that we can call
ToString() to get the message for the assert.
&lt;/p&gt;
&lt;p&gt;
void Assert&amp;lt;T&amp;gt;(T obj, Expression&amp;lt;Func&amp;lt;T, bool&amp;gt;&amp;gt; test)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp; System.Diagnostics.Debug.Assert(test.Compile().Invoke(obj), test.ToString());&lt;br&gt;
}
&lt;/p&gt;
&lt;p&gt;
This is then called like:
&lt;/p&gt;
&lt;p&gt;
Assert(input, i =&amp;gt; i != null);
&lt;/p&gt;
&lt;p&gt;
Given this idea, we can play with the syntax a bit. Using an extension method:
&lt;/p&gt;
&lt;p&gt;
static class Exts&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void MustSatisfy&amp;lt;T&amp;gt;(this T obj, Expression&amp;lt;Func&amp;lt;T,
bool&amp;gt;&amp;gt; test)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Assert(test.Compile().Invoke(obj),
test.ToString());&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
} 
&lt;p&gt;
We then have: 
&lt;p&gt;
input.MustSatisfy(i =&amp;gt; i != null) 
&lt;p&gt;
Another syntax option would be something like: 
&lt;p&gt;
Assert.That(foo).Satisfies(&lt;br&gt;
&amp;nbsp; i =&amp;gt; i &amp;gt; 0,&lt;br&gt;
&amp;nbsp; i =&amp;gt; i &amp;lt; 100); 
&lt;p&gt;
Where we are now passing an array of assertions (using a params arg in the Satisfies
method).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=f5a854c2-f0d2-4f3b-8ba6-055e3546c816" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,f5a854c2-f0d2-4f3b-8ba6-055e3546c816.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>linq</category>
      <category>programming</category>
      <category>syntax</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=d9660556-29e4-4b45-b420-d42ef678d63e</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,d9660556-29e4-4b45-b420-d42ef678d63e.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,d9660556-29e4-4b45-b420-d42ef678d63e.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=d9660556-29e4-4b45-b420-d42ef678d63e</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have so far managed to avoid needing to use any fancy ORM tools. However, this doesn't
mean I like writing all the standard ADO.NET code by hand. Using C# 2.0 anonymous
methods I am able to write code like the following. (I'm not sure all of this is truly
original work; if you have already done this then sweet! I just want to share
the ideas with everyone.)
</p>
        <p>
Customer c = With.Database&lt;Customer&gt;(delegate(Database db)<br />
{<br />
    return db.ExecuteReader&lt;Customer&gt;(<br />
        "select Id, FirstName, Surname from Customer
where Id = @id", // The SQL to execute<br />
        delegate(IDbCommand cmd) // This anonymous
function is called before executing so we can add params.<br />
        {<br />
            db.AddParameter(cmd,
"@id", DbType.Int32, id);<br />
        },<br />
        delegate(IDataReader reader) // The
IDataReader returned from ExecuteReader is passed here.<br />
        {<br />
            if (reader.Read())<br />
               
return new Customer(<br />
                   
reader.GetInt32(0),<br />
                   
reader.GetString(1),<br />
                   
reader.GetString(2));<br />
            else<br />
               
return null;<br />
        });<br />
}); 
</p>
        <p>
My Database class manages the creation of a connection and optionally a transaction.
It then exposes methods to invoke SQL commands (Reader, Scalar and NonQuery). A transaction
can be automatically provided by calling With.DatabaseInTransaction( ... ) instead.
This then wraps the inputted action in a try-catch-finally block, commit and rolling
back in the usual places.
</p>
        <p>
("With" is a static class that provides convenient access to the Database object) 
</p>
        <p>
public static T DatabaseInTransaction&lt;T&gt;(Function&lt;Database, T&gt; function)<br />
{<br />
    using (Database db = new Database())<br />
    {<br />
        db.BeginTransaction();<br />
        try<br />
        {<br />
            T result = function(db);<br />
            db.CommitTransaction();<br />
            return result;<br />
        }<br />
        catch<br />
        {<br />
            db.RollbackTransaction();<br />
            throw;<br />
        }<br />
    }<br />
} 
</p>
        <p>
There are generic and non-generic versions of the functions, depending on if we want
to return a value. 
</p>
        <p>
For example, here is the non-generic ExecuteReader method from Database: 
</p>
        <p>
public void ExecuteReader(string sql, Action&lt;IDbCommand&gt; addParameters, Action&lt;IDataReader&gt;
action)<br />
{<br />
    Debug.Assert(sql != null, "sql cannot be null.");<br />
    Debug.Assert(action != null, "action cannot be null."); 
</p>
        <p>
    using (IDbCommand cmd = CreateCommand(sql))<br />
    {<br />
        if (addParameters != null)<br />
        {<br />
            addParameters(cmd);<br />
        }<br />
        using (IDataReader reader = cmd.ExecuteReader())<br />
        {<br />
            action(reader);<br />
        }<br />
    }<br />
} 
</p>
        <p>
The IDbCommand is created using the following method. Notice that we also handle assigning
the transaction if we're in one.
</p>
        <p>
IDbCommand CreateCommand(string sql)<br />
{<br />
    Debug.Assert(_connection != null &amp;&amp; _connection.State ==
ConnectionState.Open); 
</p>
        <p>
    IDbCommand cmd = _connection.CreateCommand();<br />
    cmd.CommandText = sql;<br />
    cmd.CommandType = CommandType.Text;<br />
    if (_transaction != null)<br />
    {<br />
        cmd.Transaction = _transaction;<br />
    }<br />
    return cmd;<br />
} 
</p>
        <p>
The Database class implements IDisposable, thus allowing the "using" syntax in the
With class methods. In Dispose() I close the connection, if the transaction is still
open I rollback first.
</p>
        <p>
I anyone wants the full Database and With classes drop me a line. I'm looking forward
to C# 3.0 since the improved type inference and lambda syntax will slim down the amount
of keyboard time even more!
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=d9660556-29e4-4b45-b420-d42ef678d63e" />
      </body>
      <title>Data Access Syntax Using Anonymous Methods</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,d9660556-29e4-4b45-b420-d42ef678d63e.aspx</guid>
      <link>http://www.aboutcode.net/2007/08/27/DataAccessSyntaxUsingAnonymousMethods.aspx</link>
      <pubDate>Mon, 27 Aug 2007 09:41:09 GMT</pubDate>
      <description>&lt;p&gt;
I have so far managed to avoid needing to use any fancy ORM tools. However, this doesn't
mean I like writing all the standard ADO.NET code by hand. Using C# 2.0 anonymous
methods I am able to write code like the following. (I'm not sure all of this is truly
original work; if you have already done this&amp;nbsp;then sweet! I just want to share
the ideas with everyone.)
&lt;/p&gt;
&lt;p&gt;
Customer c = With.Database&amp;lt;Customer&amp;gt;(delegate(Database db)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return db.ExecuteReader&amp;lt;Customer&amp;gt;(&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "select Id, FirstName, Surname from Customer
where Id = @id", // The SQL to execute&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delegate(IDbCommand cmd) // This anonymous
function is called before executing so we can add params.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.AddParameter(cmd,
"@id", DbType.Int32, id);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delegate(IDataReader reader) //&amp;nbsp;The
IDataReader&amp;nbsp;returned from&amp;nbsp;ExecuteReader is passed here.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (reader.Read())&lt;br&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;
return new Customer(&lt;br&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;
reader.GetInt32(0),&lt;br&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;
reader.GetString(1),&lt;br&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;
reader.GetString(2));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br&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;
return null;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;br&gt;
}); 
&lt;p&gt;
My Database class manages the creation of a connection and optionally a transaction.
It then exposes methods to invoke SQL commands (Reader, Scalar and NonQuery). A transaction
can be automatically provided by calling With.DatabaseInTransaction( ... ) instead.
This then wraps the inputted action in a try-catch-finally block, commit and rolling
back in the usual places.
&lt;/p&gt;
&lt;p&gt;
("With" is a static class that provides convenient access to the Database object) 
&lt;p&gt;
public static T DatabaseInTransaction&amp;lt;T&amp;gt;(Function&amp;lt;Database, T&amp;gt; function)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; using (Database db = new Database())&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.BeginTransaction();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T result = function(db);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.CommitTransaction();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.RollbackTransaction();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
} 
&lt;p&gt;
There are generic and non-generic versions of the functions, depending on if we want
to return a value. 
&lt;p&gt;
For example, here is the non-generic ExecuteReader method from Database: 
&lt;p&gt;
public void ExecuteReader(string sql, Action&amp;lt;IDbCommand&amp;gt; addParameters, Action&amp;lt;IDataReader&amp;gt;
action)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Assert(sql != null, "sql cannot be null.");&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Assert(action != null, "action cannot be null."); 
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; using (IDbCommand cmd = CreateCommand(sql))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (addParameters != null)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addParameters(cmd);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (IDataReader reader = cmd.ExecuteReader())&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; action(reader);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
} 
&lt;p&gt;
The IDbCommand is created using the following method. Notice that we also handle assigning
the transaction if we're in one.
&lt;/p&gt;
&lt;p&gt;
IDbCommand CreateCommand(string sql)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Assert(_connection != null &amp;amp;&amp;amp; _connection.State ==
ConnectionState.Open); 
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; IDbCommand cmd = _connection.CreateCommand();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.CommandText = sql;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.CommandType = CommandType.Text;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (_transaction != null)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.Transaction = _transaction;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return cmd;&lt;br&gt;
} 
&lt;p&gt;
The Database class implements IDisposable, thus allowing the "using" syntax in the
With class methods. In Dispose() I close the connection, if the transaction is still
open&amp;nbsp;I rollback first.
&lt;/p&gt;
&lt;p&gt;
I anyone wants the full Database and With classes drop me a line. I'm looking forward
to C# 3.0 since the improved type inference and lambda syntax will slim down the amount
of keyboard time even more!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=d9660556-29e4-4b45-b420-d42ef678d63e" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,d9660556-29e4-4b45-b420-d42ef678d63e.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>data_access</category>
      <category>programming</category>
      <category>syntax</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=5b3ee36b-5ebd-4b47-83a9-071e593106d1</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,5b3ee36b-5ebd-4b47-83a9-071e593106d1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,5b3ee36b-5ebd-4b47-83a9-071e593106d1.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=5b3ee36b-5ebd-4b47-83a9-071e593106d1</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recorded a screencast explaining my tier splitting tool for C#. It uses a Model-View-Presenter
style application to demonstrate the features of the tool.
</p>
        <p>
Check out the <a href="http://www.aboutcode.net/screencasts/tiersplit.wmv">video</a> (wmv
format, 14.8 MB)
</p>
        <p>
I'd love to get some feedback from people...
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=5b3ee36b-5ebd-4b47-83a9-071e593106d1" />
      </body>
      <title>Tier Splitting C# Screencast</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,5b3ee36b-5ebd-4b47-83a9-071e593106d1.aspx</guid>
      <link>http://www.aboutcode.net/2007/08/25/TierSplittingCScreencast.aspx</link>
      <pubDate>Sat, 25 Aug 2007 16:18:50 GMT</pubDate>
      <description>&lt;p&gt;
I recorded a screencast explaining my tier splitting&amp;nbsp;tool for C#. It uses a Model-View-Presenter
style application to demonstrate the features of the tool.
&lt;/p&gt;
&lt;p&gt;
Check out the &lt;a href="http://www.aboutcode.net/screencasts/tiersplit.wmv"&gt;video&lt;/a&gt; (wmv
format, 14.8 MB)
&lt;/p&gt;
&lt;p&gt;
I'd love to get some feedback from people...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=5b3ee36b-5ebd-4b47-83a9-071e593106d1" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,5b3ee36b-5ebd-4b47-83a9-071e593106d1.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>programming</category>
      <category>screencast</category>
      <category>tier_split</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=992199d9-96aa-42ea-a904-86fef64459f0</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,992199d9-96aa-42ea-a904-86fef64459f0.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,992199d9-96aa-42ea-a904-86fef64459f0.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=992199d9-96aa-42ea-a904-86fef64459f0</wfw:commentRss>
      <title>A (somewhat) new approach to application development</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,992199d9-96aa-42ea-a904-86fef64459f0.aspx</guid>
      <link>http://www.aboutcode.net/2007/08/14/ASomewhatNewApproachToApplicationDevelopment.aspx</link>
      <pubDate>Tue, 14 Aug 2007 13:02:43 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;I am excited about Silverlight 1.1 – very excited! Whilst all
the graphics and animations will be a wonder for creating great user experiences,
I eagerly awaiting the chance to run managed code in the browser.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;In my mind, and partially in code, I have already begun to formulate
a new way to design applications. Of course, by &lt;i style="mso-bidi-font-style: normal"&gt;new&lt;/i&gt; I
really mean stealing a bunch of existing good ideas and gluing them together!&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The first key idea is putting the users first – always. These
auto-magic, drag-n-drop data binding tools are great for quick and dirty CRUD applications,
but I am yet to see one produce an application that has great usability. We need to
start by putting ourselves in the user’s position and thinking about why they are
using our software in the first place. It is all about finding the simplest, cleanest,
more beautiful way to enable the user to get their job done. Slapping another data
grid on a page probably is the worst approach!&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;I am a new convert to the Model-View-Presenter way of writing
client applications. Although, I think, the order of coding should be Presenter-View-Model
(it does not have quite the same ring to it however). In addition, by View I mean
the view implementation, not the UI design. I always sketch the view design on paper/white
board first. I suppose using a tool like Microsoft Expression Blend would be OK as
long as you are not precious about the XAML it creates. I am never afraid to throw
out code and start afresh, so why should UI mark-up be any different? Use whatever
tools you find easiest to knock up UI prototypes and shove them under the user’s nose.
The key here is to know roughly what buttons, textboxes, etc, the UI will contain
(we can leave all the fancy colouring in to some guy in a turtle neck). Once this
is the case, we can begin the most important part of the coding: The User Interaction
Logic (UIL).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The UIL is the Presenter. The UIL says stuff like when the user
clicks this button, read this data from the UI, tell the underlying model to do something
and then tell the view to update. Whilst for some applications this level of control
may seem like overkill, I argue that having to slow down sometimes is OK. This approach
means you have to think about what the user will be doing in your application.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The best way to develop this code is by being test-driven. Create
unit tests that describe the behaviour of the Presenter in terms of how it interacts
with View and Model object-oriented interfaces. Each user story then becomes testable.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;Key tools I plan to use here are:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;Rhino Mocks – to create mock objects of Views and Models&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;Boo + my Rhino Mocks DSL – to make the unit tests easy to read
and write&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;SharpDevelop – because Boo is not readily usable in Visual Studio
yet&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;Visual Studio 2008 – to write the implementation of the Presenter
in C#&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;As awesome as the language Boo is, I just cannot stand SharpDevelop
for more than simple projects like the unit tests. Refactoring, intellisense and code-completion
are just way to well done in Visual Studio to ignore it. I have enough memory and
screen space to run VS and SD side-by-side.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;As the Presenter is written, the interfaces for the View and Model
are being fleshed out. The refactoring tool adding the methods automatically to the
interfaces usually does this.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The choice now is whether to develop the Model or the View next.
The View is a very dumb object that simply maps data to and from the UI and raises
events when the user does stuff (clicks, key presses, etc). Since Silverlight does
not have data binding yet, this may lead to somewhat tedious code. Bear in mind also
that the Presenter is meant to be doing tasks such as converting strings into numbers
and back. However, I reckon a tool can generate most of the standard mapping code.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The declarative nature of XAML means it should be easy to add
attributes to button elements that describe the event they should raise when clicked.
A tool could scan this data and write the code for me.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;If data binding was ever added to Silverlight, I would consider
creating pure “data” objects that the Presenter tells the View to bind too. No logic
would be contained within the data objects.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The Model is where things become more interesting from a software
architecture point of view. Silverlight runs in the client’s web browser. So the Presenter
is running client-side, as is the Model on which is depends. The Model is maintaining
state about the client application. For example, which check boxes are checked, which
customer is selected? However, the Model also will need to communicate with a database
running back on the server to read and write data.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;To solve this problem, I plan to use my tier splitting C# macro.
I will write the Model class as one coherent class. By coherent I mean all the data
is there and all the logic regarding the data is there. I do not believe manually
splitting the class and messing about with proxies and web services makes any business
sense. I am not developing some kind of SOA application that is to be called by numerous
different clients. I am trying to get my Model to save its valuable data on the database
that is only accessible from the web server from whence it came. This is a reasonable
tight coupling between the client and server versions of the Model. The coupling is
so tight; I argue that I do not even want to see it!&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;In the case where the data does come from a remote web service,
we &lt;i style="mso-bidi-font-style: normal"&gt;still&lt;/i&gt; have to return to the application’s
home server since Silverlight disallows cross-domain calls. It makes sense to put
any database calls/remote web services calls into the Model. The Model knows what
data it needs, so why bother moving that knowledge outside of the class only to marshal
all the data back in again.&lt;span style="FONT-SIZE: 14pt; mso-bidi-font-size: 12.0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;With LINQ being available we do not even have to pollute the Model
with database specific SQL.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The tier splitting macro will handle generating all the WCF services
and proxies. I just have to decorate the Model’s remote methods with [RunAtServer].&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;Thorough unit testing of the Model is required. It should be possible
to create a mock D-LINQ implementation. I can then make assertions about how the Model
interacts with the data layer.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;In summary, I want to have a Silverlight UI that is but a marionette
to a Presenter running client-side. This presenter has complete unit testing to describe
the different user interactions. The Presenter uses a Model object to store all data.
This Model exists on both the client and server side. However, the split implementation
is effectively invisible to the developer.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The application of adequate tooling (both 3&lt;sup&gt;rd&lt;/sup&gt; party
and custom made) will make this an excellent way to approach writing applications.
As Silverlight 1.1 becomes more complete, I will continue to expand this topic.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;font color=#000000&gt;The result should be a happier developer and, more importantly,
a happier user.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=992199d9-96aa-42ea-a904-86fef64459f0" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,992199d9-96aa-42ea-a904-86fef64459f0.aspx</comments>
      <category>.net</category>
      <category>boo</category>
      <category>c#</category>
      <category>dsl</category>
      <category>programming</category>
      <category>rhino_mocks</category>
      <category>ria</category>
      <category>silverlight</category>
      <category>tier_split</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=1a9b2bf0-e792-4de1-9d79-505a57b5db2f</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,1a9b2bf0-e792-4de1-9d79-505a57b5db2f.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,1a9b2bf0-e792-4de1-9d79-505a57b5db2f.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=1a9b2bf0-e792-4de1-9d79-505a57b5db2f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When developing a Model for an MVP architecture it needs at some point to access the
database to read and write data. When this model is running on the client-side (in
Silverlight for example) it has no access to the database. I suppose the standard
solution here is to put the data access code in a separate class running on the server.
The client then invokes this service passing the data required.
</p>
        <p>
The approach obviously works, but I don't like it. The Model contains all the data
relevant to the business problem. It has the validation logic for the data. Why do
I need to suddenly create an entirely different service just to read and write to
the database? Now with LINQ there are no code-level ties to a particular database
technology.
</p>
        <p>
The Model should be in charge of telling the database what data it needs, reading
the data and storing into its fields. When saving data the Model should tell the database
what query to execute to save the data.
</p>
        <p>
The root of the problem here is that the Model needs to be split between the client
and server sides. However, I want this to be done in such a way that the developer
is not wading through plumbing and service layers. In essence, I want this:
</p>
        <p>
[DataContract]<br />
public class Model : IModel<br />
{<br />
  [DataMember] public string CustomerName { get; set; }<br />
  [DataMember] public decimal InvoiceAmount { get; set; }<br />
  [RunAtServer]<br />
  public void Load(int id)<br />
  {<br />
    // Access database here. Get data. Save into properties.<br />
  }<br />
}
</p>
        <p>
This needs to generate two Model classes, one for the server (which is basically
the same as above) and one for the client that replaces the [RunAtServer] methods
with calls to a service object.
</p>
        <p>
I have this working! :) I have used my C# macro tool to take the above code and generate
a new file that contains the two Models, a WCF service and client proxy. These
classes are surrounded by "#IF SERVER" and "#IF !SERVER". I then have a WCF service
project and Client project that both compile the generated file. The conditional preprocessor
directives mean each project only gets what it needs.
</p>
        <p>
This is all still prototype-level code, but it does work. I am waiting on Silverlight
1.1 to have better support for WCF, so for now I'm using XBAPs to test. However, there
is nothing stopping me using WinForms for the client as well. I see this as being
a great way to write rich internet applications. I can focus on modelling the
business problem and just decorate any methods that need to be remote with an attribute.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=1a9b2bf0-e792-4de1-9d79-505a57b5db2f" />
      </body>
      <title>Tier Splitting C# Classes</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,1a9b2bf0-e792-4de1-9d79-505a57b5db2f.aspx</guid>
      <link>http://www.aboutcode.net/2007/08/08/TierSplittingCClasses.aspx</link>
      <pubDate>Wed, 08 Aug 2007 12:17:48 GMT</pubDate>
      <description>&lt;p&gt;
When developing a Model for an MVP architecture it needs at some point to access the
database to read and write data. When this model is running on the client-side (in
Silverlight for example) it has no access to the database. I suppose the standard
solution here is to put the data access code in a separate class running on the server.
The client then invokes this service passing the data required.
&lt;/p&gt;
&lt;p&gt;
The approach obviously works, but I don't like it. The Model contains all the data
relevant to the business problem. It has the validation logic for the data. Why do
I need to suddenly create an entirely different service just to read and write to
the database? Now with LINQ there are no code-level ties to a particular database
technology.
&lt;/p&gt;
&lt;p&gt;
The Model should be in charge of telling the database what data it needs, reading
the data and storing into its fields. When saving data the Model should tell the database
what query to execute to save the data.
&lt;/p&gt;
&lt;p&gt;
The root of the problem here is that the Model needs to be split between the client
and server sides. However, I want this to be done in such a way that the developer
is not wading through plumbing and service layers. In essence, I want this:
&lt;/p&gt;
&lt;p&gt;
[DataContract]&lt;br&gt;
public class Model : IModel&lt;br&gt;
{&lt;br&gt;
&amp;nbsp; [DataMember] public string CustomerName { get; set; }&lt;br&gt;
&amp;nbsp; [DataMember] public decimal InvoiceAmount { get; set; }&lt;br&gt;
&amp;nbsp; [RunAtServer]&lt;br&gt;
&amp;nbsp; public void Load(int id)&lt;br&gt;
&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // Access database here. Get data. Save into properties.&lt;br&gt;
&amp;nbsp; }&lt;br&gt;
}
&lt;/p&gt;
&lt;p&gt;
This needs to generate two Model classes, one for the server&amp;nbsp;(which is basically
the same as above) and one for the client that replaces the [RunAtServer] methods
with calls to a service object.
&lt;/p&gt;
&lt;p&gt;
I have this working! :) I have used my C# macro tool to take the above code and generate
a new file that contains the two Models,&amp;nbsp;a WCF service and client proxy. These
classes are surrounded by "#IF SERVER" and "#IF !SERVER". I then have a WCF service
project and Client project that both compile the generated file. The conditional preprocessor
directives mean each project only gets what it needs.
&lt;/p&gt;
&lt;p&gt;
This is all still prototype-level code, but it does work. I am waiting on Silverlight
1.1 to have better support for WCF, so for now I'm using XBAPs to test. However, there
is nothing stopping me using WinForms for the client as well. I see this as being
a great way to write rich&amp;nbsp;internet applications. I can focus on modelling the
business problem and just decorate any methods that need to be remote with an attribute.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=1a9b2bf0-e792-4de1-9d79-505a57b5db2f" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,1a9b2bf0-e792-4de1-9d79-505a57b5db2f.aspx</comments>
      <category>.net</category>
      <category>c#</category>
      <category>programming</category>
      <category>tier_split</category>
      <category>ria</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=e9daab36-aecf-40c7-b531-90452f2ffe04</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,e9daab36-aecf-40c7-b531-90452f2ffe04.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,e9daab36-aecf-40c7-b531-90452f2ffe04.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=e9daab36-aecf-40c7-b531-90452f2ffe04</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
After a late night hacking session, I finally have a working syntactic macro system
for C#! It is comprised of a VS custom tool that uses the <a href="http://www.codeplex.com/csparser/">CSparser</a>.
The end result allows me to do this:
</p>
        <p>
using System;<br />
[Macro(AutoClass)]<br />
public interface IModel<br />
{<br />
  string FirstName { get; set; }<br />
  string Surname { get; set; }<br />
  int ID { get; }<br />
  event EventHandler FirstNameChanged;<br />
  event EventHandler SurnameChanged;<br />
}
</p>
        <p>
The CustomTool property of the IModel.cs file is set to "MacroExpander" and the Build
action is set to None. This then generates a new file "under" the source file, called
for example "IModel.generated.cs". This generated file contains the original interface
(minus the bogus attribute) and a new class called "Model" that provides a stanard
implementation of IModel. It includes private fields, a constructor, properties, events
and event raising methods. The class is partial so you can still create a file called
"Model.cs" alongside the interface and implement any methods. In addition, if you
enter implementations of the interface properties/events in Model.cs then the generated
class will not contain them. So it is easy to generate the 80% of standard members
and custom write the others as required.
</p>
        <p>
The sharp-minded out there will note that "AutoClass" is a parameter passed to the
Macro attribute. The expansion process is able to load any IMacro implementation I
care to write. The macro implementation is handed the parsed source tree and allowed
to modify it as required. After all macros have expanded, the source tree is
converted back to CS source text and outputted from the VS custom tool. This generated
file is compiled by VS as usual.
</p>
        <p>
I'm going to start using this AutoClass macro to generate most of my Model code (in
the Model-View-Presenter architecture). Anywhere else I need code generation at this
level I can create more macros easily.
</p>
        <p>
If people are interested in seeing this product released in some way please get in
contact. I will perhaps get a screen cast made up to show it in action.
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=e9daab36-aecf-40c7-b531-90452f2ffe04" />
      </body>
      <title>C# Syntactic Macros</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,e9daab36-aecf-40c7-b531-90452f2ffe04.aspx</guid>
      <link>http://www.aboutcode.net/2007/07/31/CSyntacticMacros.aspx</link>
      <pubDate>Tue, 31 Jul 2007 12:04:41 GMT</pubDate>
      <description>&lt;p&gt;
After a late night hacking session, I finally have a working syntactic macro system
for C#! It is comprised of a VS custom tool that uses the &lt;a href="http://www.codeplex.com/csparser/"&gt;CSparser&lt;/a&gt;.
The end result allows me to do this:
&lt;/p&gt;
&lt;p&gt;
using System;&lt;br&gt;
[Macro(AutoClass)]&lt;br&gt;
public interface IModel&lt;br&gt;
{&lt;br&gt;
&amp;nbsp; string FirstName { get; set; }&lt;br&gt;
&amp;nbsp; string Surname { get; set; }&lt;br&gt;
&amp;nbsp; int ID { get; }&lt;br&gt;
&amp;nbsp; event EventHandler FirstNameChanged;&lt;br&gt;
&amp;nbsp; event EventHandler SurnameChanged;&lt;br&gt;
}
&lt;/p&gt;
&lt;p&gt;
The CustomTool property of the IModel.cs file is set to "MacroExpander" and the Build
action is set to None. This then generates a new file "under" the source file, called
for example "IModel.generated.cs". This generated file contains the original interface
(minus the bogus attribute) and a new class called "Model" that provides a stanard
implementation of IModel. It includes private fields, a constructor, properties, events
and event raising methods. The class is partial so you can still create a file called
"Model.cs" alongside the interface and implement any methods. In addition, if you
enter implementations of the interface properties/events in Model.cs then the generated
class will not contain them. So it is easy to generate the 80% of standard members
and custom write the others as required.
&lt;/p&gt;
&lt;p&gt;
The sharp-minded out there will note that "AutoClass" is a parameter passed to the
Macro attribute. The expansion process is able to load any IMacro implementation I
care to write. The macro implementation is handed the parsed source tree and allowed
to modify it as required. After all macros have expanded, the&amp;nbsp;source tree is
converted back to CS source text and outputted from the VS custom tool. This generated
file is compiled by VS as usual.
&lt;/p&gt;
&lt;p&gt;
I'm going to start using this AutoClass macro to generate most of my Model code (in
the Model-View-Presenter architecture). Anywhere else I need code generation at this
level I can create more macros easily.
&lt;/p&gt;
&lt;p&gt;
If people are interested in seeing this product released in some way please get in
contact. I will perhaps get a screen cast made up to show it in action.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=e9daab36-aecf-40c7-b531-90452f2ffe04" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,e9daab36-aecf-40c7-b531-90452f2ffe04.aspx</comments>
      <category>.net</category>
      <category>programming</category>
      <category>c#</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=22f4a0bf-c4cc-4241-9e44-ead51b136b1a</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,22f4a0bf-c4cc-4241-9e44-ead51b136b1a.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,22f4a0bf-c4cc-4241-9e44-ead51b136b1a.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=22f4a0bf-c4cc-4241-9e44-ead51b136b1a</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have attached the Boo code containing the Rhino Mocks DSL I'm currently working
on. This is very much a work in progress release, just to get it out there. Please
have a play and tell me what you think. Happy Mocking!
</p>
        <p>
          <a href="http://www.aboutcode.net/content/binary/Dsl.boo">Dsl.boo (3.4 KB)</a>
        </p>
        <p>
To use the DSL, add the following in your code to import the static methods into scope.
</p>
        <p>
          <font face="Courier New">import Rhino.Mocks.Dsl</font>
        </p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=22f4a0bf-c4cc-4241-9e44-ead51b136b1a" />
      </body>
      <title>Code for the Rhino Mock DSL</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,22f4a0bf-c4cc-4241-9e44-ead51b136b1a.aspx</guid>
      <link>http://www.aboutcode.net/2007/07/06/CodeForTheRhinoMockDSL.aspx</link>
      <pubDate>Fri, 06 Jul 2007 12:19:48 GMT</pubDate>
      <description>&lt;p&gt;
I have attached the Boo code containing the Rhino Mocks DSL I'm currently working
on. This is very much a work in progress release, just to get it out there. Please
have a play and tell me what you think. Happy Mocking!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.aboutcode.net/content/binary/Dsl.boo"&gt;Dsl.boo (3.4 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
To use the DSL, add the following in your code to import the static methods into scope.
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;import Rhino.Mocks.Dsl&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=22f4a0bf-c4cc-4241-9e44-ead51b136b1a" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,22f4a0bf-c4cc-4241-9e44-ead51b136b1a.aspx</comments>
      <category>.net</category>
      <category>boo</category>
      <category>dsl</category>
      <category>mock_objects</category>
      <category>programming</category>
      <category>rhino_mocks</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=9126ea1f-4fcd-438b-a8f1-8f040fdc5b53</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,9126ea1f-4fcd-438b-a8f1-8f040fdc5b53.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,9126ea1f-4fcd-438b-a8f1-8f040fdc5b53.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=9126ea1f-4fcd-438b-a8f1-8f040fdc5b53</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I thought some more about the syntax of my Rhino Mock DSL. It can feel unnatural putting
all the mock expectation code before the call to the object being tested. I came up
with this working prototype instead:
</p>
        <p>
          <font face="Courier New">[Test]<br />
def Get_data_objects_for_nonexistent_company_throws():<br />
    with_mocks:<br />
        database = mocks.CreateMock[of IDatabase]()<br />
        userProvider = StubUserProvider("andrew",
"bad corp")<br />
        userProvider.MakeCurrent()<br /><br />
        execute:<br />
            uds = UserDataService(database,
userProvider)<br />
            expect_throw FaultException[of
GetDataObjectsFault]:<br />
               
uds.GetDataObjects()<br />
            assert thrown_exception.Detail.Type.Equals(GetDataObjectsFaultType.InvalidCompany)<br /><br />
        assuming:<br />
            database.GetUserID("andrew",
"bad corp")<br />
            returned 1<br />
        assuming:<br />
            database.GetCompanyID("bad
corp")<br />
            returned 0 # returning
0 from database implies nonexistent company.</font>
        </p>
        <p>
          <font face="ver">The <font face="Courier New">with_mocks</font> method sets up the
mock repository and a Store object. The <font face="Courier New">execute</font> and <font face="Courier New">assumption</font> methods
then put their blocks into the Store. At the end of <font face="Courier New">with_mocks</font> I
iterate through assumptions calling each to set up the Rhino Mock expectations. Following
that is: <font face="Courier New">mocks.ReplayAll()</font>, call to the "execute"
block, then <font face="Courier New">mocks.VerifyAll()</font>.</font>
        </p>
        <p>
The other clever bit in there is the <font face="Courier New">expect_throw</font> method.
This runs the block inside a <font face="Courier New">try...except</font> and fails
if no exception (or wrong exception type) is thrown. It puts the exception object
into field that is readable using <font face="Courier New">thrown_exception</font>.
This means we can then test assertions about the exception contents. I had to cheat
a bit and declare <font face="Courier New">thrown_exception</font> as "duck" in Boo
i.e. it is late bound. This is so we can access members on the actual object despite
not really knowing about it at compile time.
</p>
        <p>
I like the readability now. The outline is:
</p>
        <ul>
          <li>
Initialize mocks and data objects</li>
          <li>
Call the object being tested</li>
          <li>
Assert about the result</li>
          <li>
State the assumptions about how dependencies are used</li>
        </ul>
        <p>
The key bit, I feel, is that the call to the object being tested is not buried down
at the bottom of the method.
</p>
        <p>
How does everyone else feel about this modified approach?
</p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=9126ea1f-4fcd-438b-a8f1-8f040fdc5b53" />
      </body>
      <title>Better Syntax for Mocking</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,9126ea1f-4fcd-438b-a8f1-8f040fdc5b53.aspx</guid>
      <link>http://www.aboutcode.net/2007/07/04/BetterSyntaxForMocking.aspx</link>
      <pubDate>Wed, 04 Jul 2007 10:41:55 GMT</pubDate>
      <description>&lt;p&gt;
I thought some more about the syntax of my Rhino Mock DSL. It can feel unnatural putting
all the mock expectation code before the call to the object being tested. I came up
with this working prototype instead:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;[Test]&lt;br&gt;
def Get_data_objects_for_nonexistent_company_throws():&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; with_mocks:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; database = mocks.CreateMock[of IDatabase]()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; userProvider = StubUserProvider("andrew",
"bad corp")&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; userProvider.MakeCurrent()&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; execute:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uds = UserDataService(database,
userProvider)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; expect_throw FaultException[of
GetDataObjectsFault]:&lt;br&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;
uds.GetDataObjects()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert thrown_exception.Detail.Type.Equals(GetDataObjectsFaultType.InvalidCompany)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assuming:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; database.GetUserID("andrew",
"bad corp")&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returned 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assuming:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; database.GetCompanyID("bad
corp")&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returned 0 # returning
0 from database implies nonexistent company.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="ver"&gt;The &lt;font face="Courier New"&gt;with_mocks&lt;/font&gt; method sets up the
mock repository and a Store object. The &lt;font face="Courier New"&gt;execute&lt;/font&gt; and &lt;font face="Courier New"&gt;assumption&lt;/font&gt; methods
then put their blocks into the Store. At the end of &lt;font face="Courier New"&gt;with_mocks&lt;/font&gt; I
iterate through assumptions calling each to set up the Rhino Mock expectations. Following
that is: &lt;font face="Courier New"&gt;mocks.ReplayAll()&lt;/font&gt;, call to the "execute"
block, then &lt;font face="Courier New"&gt;mocks.VerifyAll()&lt;/font&gt;.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The other clever bit in there is the &lt;font face="Courier New"&gt;expect_throw&lt;/font&gt; method.
This runs the block inside a &lt;font face="Courier New"&gt;try...except&lt;/font&gt; and fails
if no exception (or wrong exception type) is thrown. It puts the exception object
into field that is readable using &lt;font face="Courier New"&gt;thrown_exception&lt;/font&gt;.
This means we can then test assertions about the exception contents. I had to cheat
a bit and declare &lt;font face="Courier New"&gt;thrown_exception&lt;/font&gt; as "duck" in Boo
i.e. it is late bound. This is so we can access members on the actual object despite
not really knowing about it at compile time.
&lt;/p&gt;
&lt;p&gt;
I like the readability now. The outline is:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Initialize mocks and data objects&lt;/li&gt;
&lt;li&gt;
Call the object being tested&lt;/li&gt;
&lt;li&gt;
Assert about the result&lt;/li&gt;
&lt;li&gt;
State the assumptions about how dependencies are used&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The key bit, I feel, is that the call to the object being tested is not buried down
at the bottom of the method.
&lt;/p&gt;
&lt;p&gt;
How does everyone else feel about this modified approach?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=9126ea1f-4fcd-438b-a8f1-8f040fdc5b53" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,9126ea1f-4fcd-438b-a8f1-8f040fdc5b53.aspx</comments>
      <category>.net</category>
      <category>boo</category>
      <category>dsl</category>
      <category>mock_objects</category>
      <category>programming</category>
      <category>rhino_mocks</category>
    </item>
    <item>
      <trackback:ping>http://www.aboutcode.net/Trackback.aspx?guid=40883495-3f6a-4bcc-885b-8a6b132bc53a</trackback:ping>
      <pingback:server>http://www.aboutcode.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.aboutcode.net/PermaLink,guid,40883495-3f6a-4bcc-885b-8a6b132bc53a.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.aboutcode.net/CommentView,guid,40883495-3f6a-4bcc-885b-8a6b132bc53a.aspx</wfw:comment>
      <wfw:commentRss>http://www.aboutcode.net/SyndicationService.asmx/GetEntryCommentsRss?guid=40883495-3f6a-4bcc-885b-8a6b132bc53a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently learnt that Boo now supports a <a href="http://jira.codehaus.org/browse/BOO-835">DSL-friendly
syntax</a>. A while back I created (and almost finished!) a set of syntactic macros
in Boo to make using Rhino Mocks much more natural. Creating macros can be hard work
though and gets pretty hacky in places.
</p>
        <p>
The new DSL-friendly syntax in Boo means I can achieve 80% of the same easy-reading
code, but using only methods and blocks!
</p>
        <p>
In about 10 minutes I whipped up this:
</p>
        <p>
          <font face="Courier New">namespace ConsoleDemo </font>
        </p>
        <p>
          <font face="Courier New">import System<br />
import Rhino.Mocks<br />
import Rhino.Mocks.BooDsl.MockDsl </font>
        </p>
        <p>
          <font face="Courier New">interface IModel:<br />
    def CalculateScore(input as int) as int<br />
interface IView:<br />
    def DisplayScore(score as int)<br />
interface IPresenter:<br />
    def Init()<br /><br />
class Presenter(IPresenter):<br />
    _model as IModel<br />
    _view as IView<br />
    def constructor(model as IModel, view as IView):<br />
        _model = model<br />
        _view = view<br />
    def Init():<br />
        score = _model.CalculateScore(0)<br />
        _view.DisplayScore(score)<br /><br />
def Test_presenter_init():<br />
    with_mocks:<br />
        // Create mocks of the dependencies<br />
        model = Mocks.CreateMock of IModel()<br />
        view = Mocks.CreateMock of IView()<br />
        // Create the object we are testing<br />
        presenter = Presenter(model, view)<br />
        // Record what we expect the presenter
to 
<br />
        // do with its dependencies.<br />
        record:<br />
            expect:<br />
               
model.CalculateScore(0)<br />
               
// Set the return value for the 
<br />
               
// previous mock call.<br />
               
mock_return 42<br />
            expect:<br />
               
view.DisplayScore(42)<br />
        // Now tell the presenter to do its stuff, 
<br />
        // so we can verify it behaves correctly.<br />
        verify:<br />
            presenter.Init()<br />
print "testing..."<br />
Test_presenter_init()<br />
print "all good!"<br />
print "Press any key to continue . . . "<br />
Console.ReadKey(true)</font>
        </p>
        <p>
The import of "Rhino.Mocks.BooDsl.MockDsl" brings some new methods into scope. with_mocks
initializes a MockRepository. "Mocks" is actually a property referencing that repository,
so we can call CreateMock, etc, on it. The record and verify methods make use of the
Mocks.Record() and Mocks.Playback() methods. I prefer using "verify" to "playback".
The "expect" method runs the code in its block, usually that invokes some mock method.
It then calls "LastCall.Repeat.Once()" to set up the expectation. The "mock_return"
method calls "LastCall.Return(value)" to set up the return value for the last mock
call.
</p>
        <p>
This is all a bit messy for now I know. I have just being throwing code down into
this prototype to get a feel for what is possible. I reckon this could be really useful
for people using Rhino Mocks.
</p>
        <p>
If you like what you've seen or have any ideas let me know.
</p>
        <p>
The DSL methods are as follows:<br />
I am aware of more than one glaring danger in the code(!) but it does show what can
be done.
</p>
        <p>
          <font face="Courier New">namespace Rhino.Mocks.BooDsl </font>
        </p>
        <p>
          <font face="Courier New">import System<br />
import Rhino.Mocks </font>
        </p>
        <p>
          <font face="Courier New">callable Block()<br /><br />
static class MockDsl: </font>
        </p>
        <p>
          <font face="Courier New">    private static _instance as MockDslImpl<br />
    static def with_mocks(b as Block):<br />
        _instance = MockDslImpl()<br />
        b()<br />
        _instance = null<br />
    static def record(b as Block):<br />
        assert _instance != null<br />
        _instance.Record(b)<br />
    static def verify(b as Block):<br />
        assert _instance != null<br />
        _instance.Verify(b)<br />
    static def expect(b as Block):<br />
        assert _instance != null<br />
        _instance.Expect(b)<br />
    static def mock_return(value as object):<br />
        assert _instance != null<br />
        _instance.MockReturn(value)<br />
    static Mocks as MockRepository:<br />
        get:<br />
            assert _instance
!= null<br />
            return _instance.Mocks </font>
        </p>
        <p>
          <font face="Courier New">    private class MockDslImpl:<br />
        mocks as MockRepository<br />
        def constructor():<br />
            mocks = MockRepository()<br />
        public Mocks as MockRepository:<br />
            get:<br />
               
return mocks<br />
        public def Record(b as Block):<br />
            using mocks.Record():<br />
               
b()<br />
        public def Verify(b as Block):<br />
            using mocks.Playback():<br />
               
b()<br />
        public def Expect(b as Block):<br />
            b()<br />
            LastCall.Repeat.Once()<br />
        public def MockReturn(value as object):<br />
            LastCall.Return(value)</font>
        </p>
        <img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=40883495-3f6a-4bcc-885b-8a6b132bc53a" />
      </body>
      <title>Rhino Mocks DSL in Boo</title>
      <guid isPermaLink="false">http://www.aboutcode.net/PermaLink,guid,40883495-3f6a-4bcc-885b-8a6b132bc53a.aspx</guid>
      <link>http://www.aboutcode.net/2007/07/02/RhinoMocksDSLInBoo.aspx</link>
      <pubDate>Mon, 02 Jul 2007 23:03:52 GMT</pubDate>
      <description>&lt;p&gt;
I recently learnt that Boo now supports a &lt;a href="http://jira.codehaus.org/browse/BOO-835"&gt;DSL-friendly
syntax&lt;/a&gt;. A while back I created (and almost finished!) a set of syntactic macros
in Boo to make using Rhino Mocks much more natural. Creating macros can be hard work
though and gets pretty hacky in places.
&lt;/p&gt;
&lt;p&gt;
The new DSL-friendly syntax in Boo means I can achieve 80% of the same easy-reading
code, but using only&amp;nbsp;methods and blocks!
&lt;/p&gt;
&lt;p&gt;
In about 10 minutes I whipped up this:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;namespace ConsoleDemo &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;import System&lt;br&gt;
import Rhino.Mocks&lt;br&gt;
import Rhino.Mocks.BooDsl.MockDsl &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;interface IModel:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def CalculateScore(input as int) as int&lt;br&gt;
interface IView:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def DisplayScore(score as int)&lt;br&gt;
interface IPresenter:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def Init()&lt;br&gt;
&lt;br&gt;
class Presenter(IPresenter):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; _model as IModel&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; _view as IView&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def constructor(model as IModel, view as IView):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _model = model&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _view = view&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def Init():&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; score = _model.CalculateScore(0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _view.DisplayScore(score)&lt;br&gt;
&lt;br&gt;
def Test_presenter_init():&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; with_mocks:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Create mocks of the dependencies&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model = Mocks.CreateMock of IModel()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; view = Mocks.CreateMock of IView()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Create the object we are testing&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; presenter = Presenter(model, view)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Record what we expect the presenter
to 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // do with its dependencies.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; record:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; expect:&lt;br&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;
model.CalculateScore(0)&lt;br&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;
// Set the return value for the 
&lt;br&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;
// previous mock call.&lt;br&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;
mock_return 42&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; expect:&lt;br&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;
view.DisplayScore(42)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Now tell the presenter to do its stuff, 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // so we can verify it behaves correctly.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; verify:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; presenter.Init()&lt;br&gt;
print "testing..."&lt;br&gt;
Test_presenter_init()&lt;br&gt;
print "all good!"&lt;br&gt;
print "Press any key to continue . . . "&lt;br&gt;
Console.ReadKey(true)&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The import of "Rhino.Mocks.BooDsl.MockDsl" brings some new methods into scope. with_mocks
initializes a MockRepository. "Mocks" is actually a property referencing that repository,
so we can call CreateMock, etc, on it. The record and verify methods make use of the
Mocks.Record() and Mocks.Playback() methods. I prefer using "verify" to "playback".
The "expect" method runs the code in its block, usually that invokes some mock method.
It then calls "LastCall.Repeat.Once()" to set up the expectation. The "mock_return"
method calls "LastCall.Return(value)" to set up the return value for the last mock
call.
&lt;/p&gt;
&lt;p&gt;
This is all a bit messy for now I know. I have just being throwing code down into
this prototype to get a feel for what is possible. I reckon this could be really useful
for people using Rhino Mocks.
&lt;/p&gt;
&lt;p&gt;
If you like what you've seen or have any ideas let me know.
&lt;/p&gt;
&lt;p&gt;
The DSL methods are as follows:&lt;br&gt;
I am aware of more than one glaring danger in the code(!) but it does show what can
be done.
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;namespace Rhino.Mocks.BooDsl &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;import System&lt;br&gt;
import Rhino.Mocks &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;callable Block()&lt;br&gt;
&lt;br&gt;
static class MockDsl: &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static _instance as MockDslImpl&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; static def with_mocks(b as Block):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _instance = MockDslImpl()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _instance = null&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; static def record(b as Block):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert _instance != null&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _instance.Record(b)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; static def verify(b as Block):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert _instance != null&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _instance.Verify(b)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; static def expect(b as Block):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert _instance != null&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _instance.Expect(b)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; static def mock_return(value as object):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert _instance != null&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _instance.MockReturn(value)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; static Mocks as MockRepository:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert _instance
!= null&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return _instance.Mocks &lt;/font&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private class MockDslImpl:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mocks as MockRepository&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def constructor():&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mocks = MockRepository()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Mocks as MockRepository:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get:&lt;br&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;
return mocks&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public def Record(b as Block):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using mocks.Record():&lt;br&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;
b()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public def Verify(b as Block):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using mocks.Playback():&lt;br&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;
b()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public def Expect(b as Block):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LastCall.Repeat.Once()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public def MockReturn(value as object):&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LastCall.Return(value)&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.aboutcode.net/aggbug.ashx?id=40883495-3f6a-4bcc-885b-8a6b132bc53a" /&gt;</description>
      <comments>http://www.aboutcode.net/CommentView,guid,40883495-3f6a-4bcc-885b-8a6b132bc53a.aspx</comments>
      <category>.net</category>
      <category>boo</category>
      <category>dsl</category>
      <category>mock_objects</category>
      <category>programming</category>
      <category>rhino_mocks</category>
    </item>
  </channel>
</rss>