<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" version="2.0"><channel><title>John Teague's Blog</title><link>http://www.lostechies.com/blogs/johnteague/default.aspx</link><description>Take your finger off the F5 button, and slowly walk away.</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JohnTeague" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="johnteague" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><title>Implementing Domain Queries</title><link>http://www.lostechies.com/blogs/johnteague/archive/2010/01/30/implementing-domain-queries.aspx</link><pubDate>Sat, 30 Jan 2010 05:48:23 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:53365</guid><dc:creator>jcteague</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=53365</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2010/01/30/implementing-domain-queries.aspx#comments</comments><description>&lt;p&gt;My current Repository interface looks something like this:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 622px; padding-right: 5px; height: 252px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IRepository
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        T FindOne&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        T FindBy&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        IEnumerable&amp;lt;T&amp;gt; FindAllBy&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        IEnumerable&amp;lt;T&amp;gt; FindAll&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        T FindOneBy&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Save&amp;lt;T&amp;gt;(T target);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Update&amp;lt;T&amp;gt;(T target);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SaveOrUpdate&amp;lt;T&amp;gt;(T target);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Delete&amp;lt;T&amp;gt;(T target);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        IEnumerable&amp;lt;T&amp;gt; Query&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; expression);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;It’s modeled after the Repository class that Jeremy and Chad put in the early versions in Fluent NHibernate (now removed).&amp;#160; It relies almost completely on Linq expressions for where statements, which make queries very easy to write and understand.&amp;#160; Like this one:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 595px; padding-right: 5px; height: 21px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;_repository.FindBy&amp;lt;User&amp;gt;(user =&amp;gt; user.Enabled == true);&lt;/pre&gt;

&lt;p&gt;This works great for small where statements, but when you need more control over the query, the current implementation doesn’t really allow you to fully take advantage of NHibernate or the Linq provider.&amp;#160; Another downside is your code is not really DRY when you have small where statements littered everywhere. &lt;/p&gt;

&lt;p&gt;So to solve these problems I implemented a very simple Domain Query pattern.&amp;#160; Domain Queries are classes that encapsulate complicated or common queries into self contained objects that can be reused throughout your application.&amp;#160; I had some very simple goals for this implementation:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Keep it simple to access from the executing code. &lt;/li&gt;

  &lt;li&gt;I wanted full access to all of Nhibernate’s functionality when I needed it. &lt;/li&gt;

  &lt;li&gt;Keep it testable. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So Let’s start with the end and then show the beginning.&amp;#160; I wanted it really simple to access a domain query.&amp;#160; This is what I had in mind for executing a domain query:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;_repostiory.FindAll(Queries.GetAllActiveUsers());&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;To&amp;#160; get there I started with a really simple interface.&amp;#160; Because there were two basic queries I wanted to execute: return a single object or a collection of an object (I don’t have a use case for things like GetScalar yet)&amp;#160; I need two methods on my interface:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IDomainQuery&amp;lt;T&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   T ExecuteUniqueResult(ISession session);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   IEnumerable&amp;lt;T&amp;gt; ExecuteList(ISession session);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;I then added the following methods to my Repository:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 643px; padding-right: 5px; height: 162px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T FindOne&amp;lt;T&amp;gt;(IDomainQuery&amp;lt;T&amp;gt; query)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; query.ExecuteUniqueResult(Session);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt; Query&amp;lt;T&amp;gt;(IDomainQuery&amp;lt;T&amp;gt; query)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; query.ExecuteList(Session);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;/pre&gt;

&lt;p&gt;My repository is responsible for knowing how to access the session.&amp;#160; Passing the ISession object to the domain query helps me meet two of my goals, I have full access to everything on the session and it is easy to test my domain queries since they are not responsible for managing the Unit of Work.&amp;#160; I can create different UoW contexts in my application and my integration tests.&lt;/p&gt;

&lt;p&gt;To create the domain queries, I use the Template pattern to abstract the IDomainQuery aspects and allow the concrete classes only deal with the query construction.&amp;#160; I have two abstract classes right now: LinqDomainQuery and CriteriaDomainQuery.&amp;#160; It’s pretty obvious what each of these do.&amp;#160; The CriteriaDomainQuery utilizes the DetachedCriteria functionality.&amp;#160; The LinqDomainQuery obviously utilizes the Linq provider.&amp;#160; I could easily create an HQLDomainQuery and an SQLDomainQuery as well, but following YAGNI I don’t need them yet.&amp;#160; Here is the LinqDomainQuery:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; LinqDomainQuery&amp;lt;TResult&amp;gt; : IDomainQuery&amp;lt;TResult&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; IQueryable&amp;lt;TResult&amp;gt; GetQuery(ISession session);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; TResult ExecuteUniqueResult(ISession session)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetQuery(session).SingleOrDefault();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IEnumerable&amp;lt;TResult&amp;gt; ExecuteList(ISession session)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetQuery(session).ToList();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Some important things to Note:&amp;#160; Notice that I call the SingleOrDefault() and ToList() methods.&amp;#160; This keeps me from having deferred execution bugs crop up.&amp;#160; I had some issues during testing because I was closing the session faster than I was actually executing the query.&amp;#160; Doing that here prevented that from happening.&amp;#160; Also notice that it the generic type is TResult.&amp;#160; With the Select statement, you can perform projections very easily. I can return DTO data directly from the query, giving me precisely the SQL statement I need and no need to map between complicated Entities to flattened DTOS.&lt;/p&gt;

&lt;p&gt;Here is an example of&amp;#160; selecting a DTO from a Linq Query:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 674px; padding-right: 5px; height: 585px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; LoadBuilderDataQuery : LinqDomainQuery&amp;lt;LoadBuilderData&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _page;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _rows;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; LoadBuilderDataQuery(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; page, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; rows)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        _page = page;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        _rows = rows;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; IQueryable&amp;lt;LoadBuilderData&amp;gt; GetQuery(ISession session)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            session.Linq&amp;lt;OrderTicket&amp;gt;()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                .Skip(_page*_rows).Take(_rows)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                .Select(t =&amp;gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LoadBuilderData()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                 {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     LoadId = t.Id,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     PromisedDate = t.PromisedDate,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     Address = t.Destination.Address1,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     City = t.Destination.City,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     State = t.Destination.State,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     Zip = t.Destination.Zip,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     CustomerName = t.Order.Customer.CustomerName,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     StoreNumber = t.FulfillingStore.StoreNumber,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     OrderNumber = t.Order.OrderNumber,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                     OrderSuffix = t.OrderSuffix
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                 });
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;           
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                       
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                                            
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;I have fully tested this query as well.&amp;#160; Here is an example, I’m leaving some of the setup and UoW handling out for brevity, you can get the idea.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 796px; padding-right: 5px; height: 210px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;//do some setup in the base class&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; when_retrieving_first_result_set : LoadBuilderQueryTests
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #008000"&gt;//unit of work helper opens and closes the session for me&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Because of =
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        () =&amp;gt; result = UnitOfWorkHelper.Use(session =&amp;gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LoadBuilderDataQuery(0, 10).ExecuteList(session));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; It should_return_10_rows = () =&amp;gt; result.ToArray().Length.Should().Equal(10);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; It should_return_LoadBuilderData =
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        () =&amp;gt; result.ToArray()[0].Should().Be.OfType(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (LoadBuilderData));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160; Here is the SQL Query generated:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/johnteague/domain_5F00_query_5F00_sql_5F00_3794BB00.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="domain_query_sql" border="0" alt="domain_query_sql" src="http://www.lostechies.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/johnteague/domain_5F00_query_5F00_sql_5F00_thumb_5F00_0BE681B5.png" width="761" height="296" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now back to the beginning.&amp;#160; To reduce some of the complexity of calling these classes, I wrapped then in static methods to make them easier to call:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 662px; padding-right: 5px; height: 180px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Queries
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; IDomainQuery&amp;lt;LoadBuilderData&amp;gt; GetLoadBuilderData(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; page, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; row)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;       &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LoadBuilderDataQuery([page, row);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;This is just some syntactic sugar, but small things like that keep your application easy to read and understand.&lt;/p&gt;

&lt;p&gt;This is a very simple way to implement domain queries.&amp;#160;&amp;#160; You can go a lot further with this.&amp;#160; &lt;a href="http://lunaverse.wordpress.com/"&gt;Tim Scott&lt;/a&gt; took my simple approach and really took the training wheels off.&amp;#160; If I can’t get him to post about it it will.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Implementing+Domain+Queries&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2010%2f01%2f30%2fimplementing-domain-queries.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2010%2f01%2f30%2fimplementing-domain-queries.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=53365" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/DDD/default.aspx">DDD</category><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/linq/default.aspx">linq</category></item><item><title>Brown Bag It To Pablo’s Fiesta</title><link>http://www.lostechies.com/blogs/johnteague/archive/2010/01/29/byof-to-pablo-s-fiesta.aspx</link><pubDate>Fri, 29 Jan 2010 15:11:00 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:53174</guid><dc:creator>jcteague</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=53174</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2010/01/29/byof-to-pablo-s-fiesta.aspx#comments</comments><description>&lt;p&gt;Thanks to the generous folks, at St. Edwards PEC, the only real cost to organizing our Open Space conference is providing food.&amp;nbsp; This what the $15 registration fee is covering: food, drinks and snacks.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s important to us that whoever wants to attend shouldn&amp;rsquo;t have to sign corporate expense requests in triplicate and I hope that a $15 registration fee isn&amp;rsquo;t keeping you from coming.&lt;/p&gt;
&lt;p&gt;But, if you&amp;rsquo;re like me and really like free or you really don&amp;rsquo;t like conference food, here is a discount code that waives the registration fee.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://pablofiesta09.eventbrite.com?discount=no-food"&gt;http://pablofiesta09.eventbrite.com?discount=no-food&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This discount waives the registration fee and we will not reserve you lunch (we may have extra, but don&amp;rsquo;t count on it). BTW, lunch will be a box lunch with a sandwich &amp;amp; chips.&lt;/p&gt;
&lt;p&gt;If you have already registered and would like to use this discount just let me know and I&amp;rsquo;ll give you a refund.&lt;/p&gt;
&lt;p&gt;Remember we are capping registration at 150 and we have passed the 90 mark for registered attendees.&amp;nbsp; It is shaping up to be a great time.&amp;nbsp; Please come an join us. &lt;/p&gt;
&lt;p&gt;(funny I just realized that it isn&amp;rsquo;t 09 anymore)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Brown+Bag+It+To+Pablo%e2%80%99s+Fiesta&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2010%2f01%2f29%2fbyof-to-pablo-s-fiesta.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2010%2f01%2f29%2fbyof-to-pablo-s-fiesta.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=53174" width="1" height="1"&gt;</description></item><item><title>And Now a Word From Our Sponsors</title><link>http://www.lostechies.com/blogs/johnteague/archive/2010/01/06/and-now-a-word-from-our-sponsors.aspx</link><pubDate>Wed, 06 Jan 2010 23:33:43 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:46311</guid><dc:creator>jcteague</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=46311</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2010/01/06/and-now-a-word-from-our-sponsors.aspx#comments</comments><description>&lt;p&gt;I wanted to take a moment and thank the sponsors of&amp;#160; &lt;a href="http://fiesta.lostechies.com"&gt;Pablo’s fiesta open space conference&lt;/a&gt;.&amp;#160; People and Organizations who sponsor conferences do so because they value their community and use base.&amp;#160; This is especially so for open space conferences since there are very few “formal” presentations with PowerPoint slides and product demos.&amp;#160; We have been very lucky to have a lot support from the Friends of Pablo other companies to keep the cost low enough so the ticket price is not a barrier to attend.&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://www.pec.stedwards.edu/"&gt;St. Edward’s Professional Education Center&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;St. Ed’s PEC has been a great partner for several events in the Austin area.&amp;#160; They have graciously have donated the space for the conference.&amp;#160; Without this donation the ticket cost would be dramatically higher.&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://bing.com"&gt;Microsoft&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;Say what you want for MS, but they have been a great sponsor of community events.&amp;#160; They have helped us with the Austin Code Camp’s and Pablo’s Day of TDD.&amp;#160; It’s nice to have a reliable partner for doing events that are targets community education. Our developer evangelist, &lt;a href="http://blogs.msdn.com/PhilWheat"&gt;Phil Wheat&lt;/a&gt; had been very supportive our efforts.&lt;/p&gt;  &lt;h3&gt;Other Sponsors&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://mclaneat.com"&gt;McLane Advanced Technologies&lt;/a&gt; will be providing drinks and snacks for everyone &lt;/li&gt;    &lt;li&gt;&lt;a href="http://pragprog.com"&gt;Pragmatic Bookshelf&lt;/a&gt; will be providing some books &lt;/li&gt;    &lt;li&gt;&lt;a href="http://theloungenet.com"&gt;The Lounge&lt;/a&gt; provided advertising &lt;/li&gt;    &lt;li&gt;&lt;a href="http://infragistics.com"&gt;Infragistics&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Avenida Software (Me) &lt;/li&gt;    &lt;li&gt;Independent Software Fabrication (&lt;a href="http://www.lostechies.com/blogs/thatotherguy/default.aspx"&gt;Gregory Long&lt;/a&gt; &lt;a href="http://www.linkedin.com/in/gregoryplong"&gt;Linkedin&lt;/a&gt;) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The Conference is coming together really well.&amp;#160; 75 people have registered.&amp;#160; We are limiting space to 150, so if you are waiting to the last moment, you might want to speed that up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=And+Now+a+Word+From+Our+Sponsors&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2010%2f01%2f06%2fand-now-a-word-from-our-sponsors.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2010%2f01%2f06%2fand-now-a-word-from-our-sponsors.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=46311" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/fiesta+open-spaces/default.aspx">fiesta open-spaces</category></item><item><title>The Open Space Conference Experience</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/12/16/the-open-space-conference-experience.aspx</link><pubDate>Wed, 16 Dec 2009 05:30:32 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:39128</guid><dc:creator>jcteague</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=39128</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/12/16/the-open-space-conference-experience.aspx#comments</comments><description>&lt;p&gt;he &lt;a href="http://fiesta.lostechies.com"&gt;Los Techies Fiesta&lt;/a&gt; is shaping up to be a wonderful conference.&amp;#160; We’ve had excellent response with more than 60 people register and quite a few sponsors to help make it even better.&amp;#160; I thought I would take a moment and talk about what it's like attending and open space conference.&amp;#160; These are, of course, my experiences and one thing about an Open Space conference is that everyone’s experience will be different.&lt;/p&gt;  &lt;p&gt;If you want to learn more, visit the &lt;a href="http://www.openspaceworld.org/cgi/wiki.cgi?"&gt;Open Space wiki&lt;/a&gt; to get much better description.&lt;/p&gt;  &lt;h2&gt;The Break Room Effect*&lt;/h2&gt;  &lt;p&gt;If you have ever gone to a conference and had the most amazing, eye opening discussion in the break room between sessions, this is what an OS conference is all day.&amp;#160; It is more about a conversation amongst peers than presentational training (although there could be some of those too).&amp;#160; Most sessions will be ad-hoc conversations &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;*I know I stole that line from somewhere, but couldn’t find it again to reference it&lt;/p&gt;  &lt;h2&gt;The Schedule&lt;/h2&gt;  &lt;p&gt;We’ll be following the same schedule that I’ve seen at the few I have been too.&amp;#160; I can’t go into too much detail since I will not be the facilitator.&amp;#160; I’d rather give too little information than incorrect. On Friday we’ll have our opening session where we’ll nominate and vote for topics we find interesting and would like to discuss.&amp;#160; On Saturday we’ll have our breakout session.&amp;#160; As per one of the tenants of Open Space, it’s over when it’s over, there is no timeline for a given topic.&amp;#160; we’ll have spillover rooms setup for conversations that need to continue.&amp;#160; Then on Sunday we’ll have a few wrap up sessions and then close.&lt;/p&gt;  &lt;h2&gt;Transformational&lt;/h2&gt;  &lt;p&gt;I feel that these conferences are a truly transformational event.&amp;#160; Compared traditional conferences where I might learn a lot and (and then quickly forget as I don’t use the knowledge at work), OS conferences offer a chance to really connect with the community and work towards improving myself and the community.&lt;/p&gt;  &lt;p&gt;If you haven’t already registered I hope you will.&amp;#160; It is going to be a very fun time and I look forward to meeting everyone who does come.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=The+Open+Space+Conference+Experience&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f12%2f16%2fthe-open-space-conference-experience.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f12%2f16%2fthe-open-space-conference-experience.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=39128" width="1" height="1"&gt;</description></item><item><title>Pablo’s Fiesta: Open Space Conference in Austin TX</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/11/16/pablo-s-fiesta-open-space-conference-in-austin-tx.aspx</link><pubDate>Mon, 16 Nov 2009 21:36:27 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:31767</guid><dc:creator>jcteague</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=31767</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/11/16/pablo-s-fiesta-open-space-conference-in-austin-tx.aspx#comments</comments><description>&lt;h2&gt;Pablo's Fiesta&lt;/h2&gt;  &lt;h4&gt;&lt;strong&gt;Los Techies Open Space Conference on Software Quality &amp;amp; Craftsmanship&lt;/strong&gt; &lt;/h4&gt;  &lt;p&gt;&lt;strong&gt;When: February 26, 27 &amp;amp; 28      &lt;br /&gt;Where: St. Edward's Professional Educational Center, Austin TX&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I am proud to announce the first Los Techies Open Space Conference.&amp;#160; We’ve been working on this for a while we are now finally ready to make the public announcement.&lt;/p&gt;  &lt;p&gt;You can see all of the details and register &lt;a href="http://fiesta.lostechies.com"&gt;here&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;h3&gt;What I want the conference to be.&lt;/h3&gt;  &lt;p&gt;The great thing about Open Space conferences is that the content as well as the tenor of the conference is defined more by those attending than those who organize it.&amp;#160; Here is what I think the conference should be.&amp;#160; &lt;/p&gt;  &lt;p&gt;The topic of the conference will be focused on Software Quality and Craftsmanship.&amp;#160; This is a topic that is very near and dear to the hearts of the Los Techies crew.&amp;#160; Quality is the most important feature of any product, and can be difficult to achieve and&amp;#160; measure in software.&amp;#160; Craftsmanship is a philosophy about how professionals in our field should approach their work and how, as a profession, we should focus on cultivating a community of software developers who&amp;#160; learn, respect and give back to the profession.&lt;/p&gt;  &lt;p&gt;There are several important aspects to being a craftsman that I&amp;#160; to&amp;#160; address:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Sharpening the Saw&lt;/strong&gt;.&amp;#160; It important to learn new techniques and different technologies to continue to grow in this profession. I’m the software developer equivalent of a gear head (or petro head you you UK guys). I have no doubt there will be some technical discussions.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Multi-Platform&lt;/strong&gt;.&amp;#160; I want to talk about more the C#.&amp;#160; Let’s discuss iPhone, Ruby, Python and any other platform that help us become better software developers.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Selling Quality as a feature&lt;/strong&gt;.&amp;#160; How do we convince clients and business executives that quality is a feature of software that has a very big impact on their bottom line.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Come to the conference and influence help shape it to be to what you think it should be.&amp;#160; Please join us in Austin TX, February 26,l 27 &amp;amp; 28. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Pablo%e2%80%99s+Fiesta%3a+Open+Space+Conference+in+Austin+TX&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f11%2f16%2fpablo-s-fiesta-open-space-conference-in-austin-tx.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f11%2f16%2fpablo-s-fiesta-open-space-conference-in-austin-tx.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=31767" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/los-techies-fiesta/default.aspx">los-techies-fiesta</category></item><item><title>Making JavaScript APIs Easier to Use</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/09/16/proper-javascript-api-design.aspx</link><pubDate>Wed, 16 Sep 2009 04:21:00 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:24875</guid><dc:creator>jcteague</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=24875</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/09/16/proper-javascript-api-design.aspx#comments</comments><description>&lt;p&gt;Todd Anglin presented some of the AJAX functionality available in ASP.Net 4.0 at this months &lt;a href="http://adnug.org"&gt;ADNUG&lt;/a&gt; meeting.&amp;nbsp; One of the things he demonstrated was the Client Side binding, which is really cool (I&amp;rsquo;ll have more on this later).&amp;nbsp; In one of his code samples, he showed how the MS AJAX library call to bind an element to a datasource.&amp;nbsp; It looked odd to me at first and and I couldn&amp;rsquo;t figure out why at first.&amp;nbsp; Then on the way home, I realized that it designed completely wrong for a JavaScript function.&amp;nbsp; The function call looked something like this (I may not get this syntax completely right,it&amp;rsquo;s just an example, please don&amp;rsquo;t sweat the details).&lt;/p&gt;
&lt;div style="padding: 5px; width: 779px; display: block; float: none; margin-left: auto; margin-right: auto;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7eca06a8-2e9d-464c-b4f9-b6d37be13178" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;
&lt;p&gt;  &lt;span style="background: #000000 none repeat scroll 0% 0%; color: #ffffff;"&gt;$create(Sys.Data.DataView, {}, {}, $get(&lt;/span&gt;&lt;span style="color: #00ff00;"&gt;'identifier'&lt;/span&gt;&lt;span style="color: #ffffff;"&gt;));&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;rsquo;s a fairly simple method call. I haven&amp;rsquo;t studied the details, so I don&amp;rsquo;t know exactly what all of the parameters do.&amp;nbsp; It looks like the first parameter is the data type, the second and third are a set of options we don&amp;rsquo;t need in this example, and the last parameter is the id of the element we want to databind.&amp;nbsp; So what is wrong with this?&amp;nbsp; I am needing to declare a lot of function parameters I don&amp;rsquo;t need for normal operations.&amp;nbsp; It looks like an overload with just the element to databind would be what I would use for common usage.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;One of the cool parts in JavaScript is that I don&amp;rsquo;t need to actually overload the method.&amp;nbsp; I can call the method with just the first paramter and the others will be null.&amp;nbsp; I can deal with this possibility be creating aliases that have default values if they are null.&amp;nbsp; The shortcut syntax looks like this. &lt;/p&gt;
&lt;div style="padding: 5px; width: 779px; display: block; float: none; margin-left: auto; margin-right: auto;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d21f4f5a-293b-4f87-aaf6-2e7ac1a4b41b" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;
&lt;p&gt;  &lt;span style="background: #000000 none repeat scroll 0% 0%; color: #ff8000;"&gt;function&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; create(element, datatype, options1, options2) {&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #ff8000;"&gt;var&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; dt = datatype || Sys.Data.DataView;&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #ff8000;"&gt;var&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; op1 = options1 || {};&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #ff8000;"&gt;var&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; op2 = options2 || {};&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #00ff00;"&gt;//do something with variables now&lt;br /&gt; &lt;/span&gt;&lt;span style="color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt; &amp;nbsp; }&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;What this code is doing is setting the private variables to default values when the parameters are null.&lt;/p&gt;
&lt;p&gt;Now I could use the function like this and get the same results:&lt;/p&gt;
&lt;div style="padding: 5px; width: 779px; display: block; float: none; margin-left: auto; margin-right: auto;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:515895a1-c17d-4336-89dd-a02d07b86ecf" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;
&lt;p&gt;  &lt;span style="background: #000000 none repeat scroll 0% 0%; color: #ffffff;"&gt;$create($get(&lt;/span&gt;&lt;span style="color: #00ff00;"&gt;'identifier'&lt;/span&gt;&lt;span style="color: #ffffff;"&gt;));&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I could go further and make it even easier to on the developer by testing to see if the element is either a string or an object .&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="padding: 5px; width: 779px; display: block; float: none; margin-left: auto; margin-right: auto;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a950c903-c691-4e50-aaa2-fd0fccbc4030" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;
&lt;p&gt;  &lt;span style="background: #000000 none repeat scroll 0% 0%; color: #ff8000;"&gt;function&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; create(element, datatype, options1, options2) {&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #ff8000;"&gt;var&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; dt = datatype || Sys.Data.DataView;&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #ff8000;"&gt;var&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; op1 = options1 || {};&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #ff8000;"&gt;var&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; op2 = options2 || {};&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #ff8000;"&gt;var&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; el = &lt;/span&gt;&lt;span style="color: #ff8000;"&gt;typeof&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; (element) === &lt;/span&gt;&lt;span style="color: #00ff00;"&gt;'string'&lt;/span&gt;&lt;span style="color: #ffffff;"&gt; ? $get(element) : element;&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #00ff00;"&gt;//do something with variables now&lt;br /&gt; &lt;/span&gt;&lt;span style="color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt; &amp;nbsp; }&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now I could also use the method like this, even further reducing my cognitive load &lt;/p&gt;
&lt;div style="padding: 5px; width: 779px; display: block; float: none; margin-left: auto; margin-right: auto;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e4e8f8a0-ddfd-4d95-b32f-5b5727a25688" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;
&lt;p&gt;  &lt;span style="background: #000000 none repeat scroll 0% 0%; color: #ffffff;"&gt;$create(&lt;/span&gt;&lt;span style="color: #00ff00;"&gt;'identifier'&lt;/span&gt;&lt;span style="color: #ffffff;"&gt;);&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;JavaScript has tons of little features like these that can make really fun to use when the API designers take full advantage of what it has to offer.&amp;nbsp; Of course it does have it&amp;rsquo;s share of &amp;ldquo;&lt;a href="http://bit.ly/U4pJw"&gt;bad&lt;/a&gt;&amp;rdquo; features too.&amp;nbsp; A great API is one that knows the differences.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Making+JavaScript+APIs+Easier+to+Use&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f09%2f16%2fproper-javascript-api-design.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f09%2f16%2fproper-javascript-api-design.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=24875" width="1" height="1"&gt;</description></item><item><title>JQuery Does Not Like QuirksMode</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/09/14/jquery-does-not-like-quirksmode.aspx</link><pubDate>Tue, 15 Sep 2009 03:21:26 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:24842</guid><dc:creator>jcteague</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=24842</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/09/14/jquery-does-not-like-quirksmode.aspx#comments</comments><description>&lt;p&gt;I was helping a client out today with a JQuery issue. They were well into the development of an applications that heavily uses the JQuery UI dialog widget to show information.&amp;#160; Like most web developers they were using Firefox/Firebug for day-to-day development (because trying to develop complicated apps with IE is painful).&amp;#160; All of their dialog windows were working normally with an acceptable load time.&lt;/p&gt;  &lt;p&gt;However, when they started testing in IE, the dialogs screens were painfully slow.&amp;#160; Less than a second in Firefox was now 4+ seconds on IE.&amp;#160; We stripped it down to just a simple dialog, do nothing but displaying a div with some text and still taking a long time.&amp;#160; At this point I knew it was something inside JQuery that was causing it.&amp;#160; I didn’t think it was a bug because I’ve used them plenty of times cross browser with not problems.&amp;#160; The team further drilled into the jQuery code that was taking so long using a profiler.&amp;#160; There was some code that looked like this (not all of it)&lt;/p&gt;  &lt;div style="padding-bottom: 5px; padding-left: 5px; width: 779px; padding-right: 5px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 5px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5d915f49-ccab-42ae-8a56-dd11b6ccc570" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;
&lt;p&gt;  &lt;span style="background:#000000;color:#ff8000"&gt;return&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;this&lt;/span&gt;&lt;span style="color:#ffffff"&gt;[0] == window ?&lt;br&gt;             &lt;/span&gt;&lt;span style="color:#00ff00"&gt;// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode&lt;br&gt; &lt;/span&gt;&lt;span style="color:#ffffff"&gt;            document.compatMode == &lt;/span&gt;&lt;span style="color:#00ff00"&gt;"CSS1Compat"&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &amp;amp;&amp;amp; document.documentElement[ &lt;/span&gt;&lt;span style="color:#00ff00"&gt;"client"&lt;/span&gt;&lt;span style="color:#ffffff"&gt; + name ] ||&lt;br&gt;             document.body[ &lt;/span&gt;&lt;span style="color:#00ff00"&gt;"client"&lt;/span&gt;&lt;span style="color:#ffffff"&gt; + name ] :&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;  &lt;p&gt;document.CompatMode returns two values: “CSS1Compat” when in compatibility mode and “BackCompat” when in quirks mode. &lt;/p&gt;  &lt;p&gt;So, jQuery does something different in quirksmode than compatibility mode.&amp;#160; A quick check determined the page was being rendered in quirks mode, which forced jQuery to use some less than optimal approaches to modifying the dome elements.&amp;#160; I always knew this was the case, but I didn’t expect it to be 4 seconds of difference!!&lt;/p&gt;  &lt;p&gt;This can be avoided by specifying the &lt;a href="http://www.w3schools.com/Xhtml/xhtml_dtd.asp"&gt;DOCTYPE&lt;/a&gt; for your pages.&amp;#160; Apparently the team did look into this, but they had a comment before the doctype declaration and it &lt;strong&gt;must be the first line&lt;/strong&gt; or it will be ignored by the browser, guaranteeing quirks mode in IE.&lt;/p&gt;  &lt;p&gt;I’m sure that jQuery makes this type of check all over the place, so if you are targeting Internet Explorer I would stay in compatibility mode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=JQuery+Does+Not+Like+QuirksMode&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f09%2f14%2fjquery-does-not-like-quirksmode.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f09%2f14%2fjquery-does-not-like-quirksmode.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=24842" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/jQuery/default.aspx">jQuery</category></item><item><title>Testing Private &amp; Protected Members of a Class</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/08/28/testing-private-amp-protected-members-of-a-class.aspx</link><pubDate>Fri, 28 Aug 2009 04:48:39 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:24233</guid><dc:creator>jcteague</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=24233</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/08/28/testing-private-amp-protected-members-of-a-class.aspx#comments</comments><description>&lt;p&gt;In my last blog post, someone asked me you can write unit tests for a private or protected method.&amp;#160; I gave part of the response in a comment, but I need to give a more detailed description.&lt;/p&gt;  &lt;h2&gt;Focus on the public API of your system&lt;/h2&gt;  &lt;p&gt;First and foremost, I focus on testing the public API.&amp;#160; You should be able to test all of the code branches in your private methods by adequately testing the public methods in your system.&amp;#160; Using tools like NCover can help you analyze how well your tests are actually testing your system.&amp;#160; I don’t try to get 100% coverage, but I typically have above 80% as a normal target.&lt;/p&gt;  &lt;h2&gt;Testing Protected Members&lt;/h2&gt;  &lt;p&gt;There are times when you do need to test protected members of a class.&amp;#160; If you are inheriting from a class that you do have the source code to (like say Controller) and you override a protected method, it is possible to test that.&amp;#160; While it should be possible to test protected member through the public api, it is relatively simple to do it and doesn’t really break any encapsulation rules in your application.&lt;/p&gt;  &lt;p&gt;It is actually very easy.&amp;#160; All you need to do is create a test class that inherits from you and add a public method that call the protected method in question.&amp;#160; Here is an example.&lt;/p&gt;  &lt;div style="padding-bottom: 5px; padding-left: 5px; width: 715px; padding-right: 5px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 5px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:af166447-8297-44ee-b237-512c58dbbc60" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;
&lt;p&gt;  &lt;span style="background:#000000;color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;class&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ffff00"&gt;ClassWithProtectedMember&lt;br&gt; &lt;/span&gt;&lt;span style="color:#ffffff"&gt;    {&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;protected&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;int&lt;/span&gt;&lt;span style="color:#ffffff"&gt; UltimateQuestionAnswer() { &lt;/span&gt;&lt;span style="color:#ff8000"&gt;return&lt;/span&gt;&lt;span style="color:#ffffff"&gt; 42; }&lt;br&gt;     }&lt;br&gt; &lt;br&gt;     &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;class&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ffff00"&gt;ProtectedMemberAccessor&lt;/span&gt;&lt;span style="color:#ffffff"&gt; : &lt;/span&gt;&lt;span style="color:#ffff00"&gt;ClassWithProtectedMember&lt;br&gt; &lt;/span&gt;&lt;span style="color:#ffffff"&gt;    {&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;int&lt;/span&gt;&lt;span style="color:#ffffff"&gt; ExecuteUltimateQuestionAnswer(){&lt;br&gt;             &lt;/span&gt;&lt;span style="color:#ff8000"&gt;return&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;base&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.UltimateQuestionAnswer();}&lt;br&gt;     }&lt;br&gt;     [&lt;/span&gt;&lt;span style="color:#ffff00"&gt;TestFixture&lt;/span&gt;&lt;span style="color:#ffffff"&gt;]&lt;br&gt;     &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;class&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ffff00"&gt;ProtectedMemberSpecs&lt;/span&gt;&lt;span style="color:#ffffff"&gt; {&lt;br&gt; &lt;br&gt;         [&lt;/span&gt;&lt;span style="color:#ffff00"&gt;Test&lt;/span&gt;&lt;span style="color:#ffffff"&gt;]&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;void&lt;/span&gt;&lt;span style="color:#ffffff"&gt; should_give_us_the_answer_to_life_universe_and_everything()&lt;br&gt;         {&lt;br&gt;             &lt;/span&gt;&lt;span style="color:#ff8000"&gt;var&lt;/span&gt;&lt;span style="color:#ffffff"&gt; wrapper = &lt;/span&gt;&lt;span style="color:#ff8000"&gt;new&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ffff00"&gt;ProtectedMemberAccessor&lt;/span&gt;&lt;span style="color:#ffffff"&gt;();&lt;br&gt;             &lt;/span&gt;&lt;span style="color:#ffff00"&gt;Assert&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.That(wrapper.ExecuteUltimateQuestionAnswer(),&lt;/span&gt;&lt;span style="color:#ffff00"&gt;Is&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.EqualTo(42));&lt;br&gt;         }&lt;br&gt;     \&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;  &lt;p&gt;This is a very simple and straightforward approach, but is very effective in testing some hidden members in you system.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Testing+Private+%26amp%3b+Protected+Members+of+a+Class&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f08%2f28%2ftesting-private-amp-protected-members-of-a-class.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f08%2f28%2ftesting-private-amp-protected-members-of-a-class.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=24233" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/Testing/default.aspx">Testing</category><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/c_2300_/default.aspx">c#</category></item><item><title>The TryThis method</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/08/27/the-trythis-method.aspx</link><pubDate>Thu, 27 Aug 2009 04:19:27 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:24170</guid><dc:creator>jcteague</dc:creator><slash:comments>13</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=24170</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/08/27/the-trythis-method.aspx#comments</comments><description>&lt;p&gt;The more I learn and use dynamic languages like JavaScript and Ruby, the more I feel the constraints placed on me by the C# compiler.&amp;#160; Today I needed to wrap a bunch of calls to a web service facade in some try catch statements.&amp;#160; I really hated the idea of littering my code with these because a lot them make the code that much harder to read.&amp;#160; What I really wanted was a method that would execute the statement in a try/catch and do the necessary exception handling for me. In this situation, the method calls were very different (number of parameters, return values), but the error handling was exactly the same.&lt;/p&gt;  &lt;p&gt;What I really wanted was something like the block statement in Ruby, where I just pass in arbitrary code to a method that would then execute it.&amp;#160; It was a little trickier in C# because of the variations in the method signture.&amp;#160; A method that had a Func parameter wouldn’t work because I had varying number of parameters.&amp;#160; Also the changing return value added a nice twist.&amp;#160; In the end, it came out rather nice.&lt;/p&gt;  &lt;p&gt;With this little method I can now pass in any method and &lt;/p&gt;  &lt;div style="padding-bottom: 5px; padding-left: 5px; width: 715px; padding-right: 5px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 5px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a4d6dafa-2610-4212-a710-58a09aec9955" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;
&lt;p&gt;  &lt;span style="background:#000000;color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;private&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;bool&lt;/span&gt;&lt;span style="color:#ffffff"&gt; TryThis(&lt;/span&gt;&lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;&lt;span style="color:#ffffff"&gt; block)&lt;br&gt;         {&lt;br&gt;             &lt;/span&gt;&lt;span style="color:#ff8000"&gt;try&lt;br&gt; &lt;/span&gt;&lt;span style="color:#ffffff"&gt;            {&lt;br&gt;                 block();&lt;br&gt;                 &lt;/span&gt;&lt;span style="color:#ff8000"&gt;return&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;true&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;br&gt;             }&lt;br&gt;             &lt;/span&gt;&lt;span style="color:#ff8000"&gt;catch&lt;/span&gt;&lt;span style="color:#ffffff"&gt;(&lt;/span&gt;&lt;span style="color:#ffff00"&gt;Exception&lt;/span&gt;&lt;span style="color:#ffffff"&gt;)&lt;br&gt;             {&lt;br&gt;                 &lt;/span&gt;&lt;span style="color:#00ff00"&gt;//do something with exception here&lt;br&gt; &lt;/span&gt;&lt;span style="color:#ffffff"&gt;                &lt;/span&gt;&lt;span style="color:#ff8000"&gt;return&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;false&lt;/span&gt;&lt;span style="color:#ffffff"&gt;;&lt;br&gt;             }&lt;br&gt;         \&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;  &lt;p&gt;Here are a few tests to show what it looks like.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 5px; padding-left: 5px; width: 715px; padding-right: 5px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 5px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2084f130-bd85-4b3e-9897-35ab24a736f2" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background-color: #000000; max-height: auto; overflow: scroll; padding: 2px 5px; white-space: wrap"&gt;
&lt;p&gt;  &lt;span style="background:#000000;color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;interface&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#2b91af"&gt;Foo&lt;br&gt; &lt;/span&gt;&lt;span style="color:#ffffff"&gt;    {&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;&lt;span style="color:#ffffff"&gt; Bar(&lt;/span&gt;&lt;span style="color:#ff8000"&gt;string&lt;/span&gt;&lt;span style="color:#ffffff"&gt; a, &lt;/span&gt;&lt;span style="color:#ff8000"&gt;string&lt;/span&gt;&lt;span style="color:#ffffff"&gt; b);&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;string&lt;/span&gt;&lt;span style="color:#ffffff"&gt; Bar2(&lt;/span&gt;&lt;span style="color:#ff8000"&gt;int&lt;/span&gt;&lt;span style="color:#ffffff"&gt; a);&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;void&lt;/span&gt;&lt;span style="color:#ffffff"&gt; Bar3(&lt;/span&gt;&lt;span style="color:#ff8000"&gt;int&lt;/span&gt;&lt;span style="color:#ffffff"&gt; a, &lt;/span&gt;&lt;span style="color:#ff8000"&gt;int&lt;/span&gt;&lt;span style="color:#ffffff"&gt; b);&lt;br&gt;     }&lt;br&gt;     [&lt;/span&gt;&lt;span style="color:#ffff00"&gt;TestFixture&lt;/span&gt;&lt;span style="color:#ffffff"&gt;]&lt;br&gt;     &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;class&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ffff00"&gt;trythis_specs&lt;br&gt; &lt;/span&gt;&lt;span style="color:#ffffff"&gt;    {&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;private&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#2b91af"&gt;Foo&lt;/span&gt;&lt;span style="color:#ffffff"&gt; mock;&lt;br&gt; &lt;br&gt;         [&lt;/span&gt;&lt;span style="color:#ffff00"&gt;SetUp&lt;/span&gt;&lt;span style="color:#ffffff"&gt;]&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;void&lt;/span&gt;&lt;span style="color:#ffffff"&gt; setup()&lt;br&gt;         {&lt;br&gt;             mock = &lt;/span&gt;&lt;span style="color:#ffff00"&gt;MockRepository&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.GenerateMock&amp;lt;&lt;/span&gt;&lt;span style="color:#2b91af"&gt;Foo&lt;/span&gt;&lt;span style="color:#ffffff"&gt;&amp;gt;();&lt;br&gt;         }&lt;br&gt;        [&lt;/span&gt;&lt;span style="color:#ffff00"&gt;Test&lt;/span&gt;&lt;span style="color:#ffffff"&gt;]&lt;br&gt;        &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;void&lt;/span&gt;&lt;span style="color:#ffffff"&gt; should_return_true_when_there_is_no_exception()&lt;br&gt;        {&lt;br&gt;            mock.Stub(m =&amp;gt; m.Bar(&lt;/span&gt;&lt;span style="color:#00ff00"&gt;"a"&lt;/span&gt;&lt;span style="color:#ffffff"&gt;, &lt;/span&gt;&lt;span style="color:#00ff00"&gt;"b"&lt;/span&gt;&lt;span style="color:#ffffff"&gt;)).Return(&lt;/span&gt;&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.Now);&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;&lt;span style="color:#ffffff"&gt; output;&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#ff8000"&gt;bool&lt;/span&gt;&lt;span style="color:#ffffff"&gt; result = TryThis(() =&amp;gt; output = mock.Bar(&lt;/span&gt;&lt;span style="color:#00ff00"&gt;"a"&lt;/span&gt;&lt;span style="color:#ffffff"&gt;, &lt;/span&gt;&lt;span style="color:#00ff00"&gt;"b"&lt;/span&gt;&lt;span style="color:#ffffff"&gt;));&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#ffff00"&gt;Assert&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.That(result);&lt;br&gt; &lt;br&gt;        }&lt;br&gt;        [&lt;/span&gt;&lt;span style="color:#ffff00"&gt;Test&lt;/span&gt;&lt;span style="color:#ffffff"&gt;]&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;void&lt;/span&gt;&lt;span style="color:#ffffff"&gt; can_get_the_value_from_executing_method()&lt;br&gt;        {&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#ff8000"&gt;var&lt;/span&gt;&lt;span style="color:#ffffff"&gt; time = &lt;/span&gt;&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.Now;&lt;br&gt;            mock.Stub(m =&amp;gt; m.Bar(&lt;/span&gt;&lt;span style="color:#00ff00"&gt;"a"&lt;/span&gt;&lt;span style="color:#ffffff"&gt;, &lt;/span&gt;&lt;span style="color:#00ff00"&gt;"b"&lt;/span&gt;&lt;span style="color:#ffffff"&gt;)).Return(time);&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;&lt;span style="color:#ffffff"&gt; output = &lt;/span&gt;&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.MinValue;&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#ff8000"&gt;bool&lt;/span&gt;&lt;span style="color:#ffffff"&gt; result = TryThis(() =&amp;gt; output = mock.Bar(&lt;/span&gt;&lt;span style="color:#00ff00"&gt;"a"&lt;/span&gt;&lt;span style="color:#ffffff"&gt;, &lt;/span&gt;&lt;span style="color:#00ff00"&gt;"b"&lt;/span&gt;&lt;span style="color:#ffffff"&gt;));&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#ffff00"&gt;Assert&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.That(output, &lt;/span&gt;&lt;span style="color:#ffff00"&gt;Is&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.EqualTo(time));&lt;br&gt;        }&lt;br&gt;        [&lt;/span&gt;&lt;span style="color:#ffff00"&gt;Test&lt;/span&gt;&lt;span style="color:#ffffff"&gt;]&lt;br&gt;         &lt;/span&gt;&lt;span style="color:#ff8000"&gt;public&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ff8000"&gt;void&lt;/span&gt;&lt;span style="color:#ffffff"&gt; return_false_on_exception()&lt;br&gt;         {&lt;br&gt;            mock.Stub(m =&amp;gt; m.Bar3(1,2)).Throw(&lt;/span&gt;&lt;span style="color:#ff8000"&gt;new&lt;/span&gt;&lt;span style="color:#ffffff"&gt; &lt;/span&gt;&lt;span style="color:#ffff00"&gt;Exception&lt;/span&gt;&lt;span style="color:#ffffff"&gt;());&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#ff8000"&gt;var&lt;/span&gt;&lt;span style="color:#ffffff"&gt; result = TryThis(() =&amp;gt; mock.Bar3(1,2));&lt;br&gt;            &lt;/span&gt;&lt;span style="color:#ffff00"&gt;Assert&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.That(result, &lt;/span&gt;&lt;span style="color:#ffff00"&gt;Is&lt;/span&gt;&lt;span style="color:#ffffff"&gt;.False);&lt;br&gt;         \&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;  &lt;p&gt;That’s not quite as clean a block parameter in Ruby, but I can live with it for now. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=The+TryThis+method&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f08%2f27%2fthe-trythis-method.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f08%2f27%2fthe-trythis-method.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=24170" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/c_2300_/default.aspx">c#</category></item><item><title>Wiring Up Generics In Castle Windsor</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/08/20/wiring-up-generics-in-castle-windsor.aspx</link><pubDate>Thu, 20 Aug 2009 20:49:00 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:23916</guid><dc:creator>jcteague</dc:creator><slash:comments>9</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=23916</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/08/20/wiring-up-generics-in-castle-windsor.aspx#comments</comments><description>&lt;p&gt;I'm working with a new team that has a slightly different technology stack then I'm used to.&amp;nbsp; On most projects where I am the team lead, StructureMap is my IOC container of choice.&amp;nbsp; I've always thought that this was just laziness on my part because I can wire up most things very quickly. Now I'm beginning to think that SM has spoiled me :)&lt;/p&gt;
&lt;p&gt;I like to take advantage of open generic mapping that most of the popular containers support.&amp;nbsp; In this particular case, I've got a Generic Validator that takes in a different array of validations for a given type.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The constructor for this guy looks like this:&lt;/p&gt;
&lt;p&gt;public class ServiceValidationRunner&amp;lt;T&amp;gt; : IServiceValidationRunner&amp;lt;T&amp;gt;&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; private IValidation&amp;lt;T&amp;gt;[] _validations;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private readonly IValidationErrorHandler _errorHandler;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ServiceValidationRunner(IValidation&amp;lt;T&amp;gt;[] validations, IValidationErrorHandler errorHandler)&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; _validations = validations;&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; _errorHandler = errorHandler;&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; ...&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Here is how I'm am setting this up for two different types that have different validations:&lt;/p&gt;
&lt;p&gt;container.Register&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; //wire up the specific types with their validation rules&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; Component.For&amp;lt;IServiceValidationRunner&amp;lt;Object1&amp;gt;&amp;gt;().ImplementedBy&amp;lt;ServiceValidationRunner&amp;lt;Object1&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; .DependsOn(new {validations = new[]{new Validator1(),new Validator2}}),&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; Component.For&amp;lt;IServiceValidationRunner&amp;lt;Object2&amp;gt;&amp;gt;().ImplementedBy&amp;lt;ServiceValidationRunner&amp;lt;Object2&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; .DependsOn(new {validations = new[]{new Validator1(), new Validator3()}}),&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;);&lt;/p&gt;
&lt;p&gt;The code is pretty self explanatory, it's a simple matter of wiring up the dependencies for the specific type the generic class is wired up for.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Wiring+Up+Generics+In+Castle+Windsor&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f08%2f20%2fwiring-up-generics-in-castle-windsor.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f08%2f20%2fwiring-up-generics-in-castle-windsor.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=23916" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/Castle/default.aspx">Castle</category><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/IOC/default.aspx">IOC</category></item><item><title>Demeter Helps You Fend Off the One True Constant: Change</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/07/20/demeter-helps-you-fend-off-the-one-true-constant-change.aspx</link><pubDate>Mon, 20 Jul 2009 04:33:00 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:23095</guid><dc:creator>jcteague</dc:creator><slash:comments>11</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=23095</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/07/20/demeter-helps-you-fend-off-the-one-true-constant-change.aspx#comments</comments><description>&lt;p&gt;There have been some &lt;a href="http://haacked.com/archive/2009/07/14/law-of-demeter-dot-counting.aspx"&gt;good&lt;/a&gt; &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2009/07/18/what-i-ve-learned-over-the-last-five-years.aspx"&gt;discussion&lt;/a&gt; lately around the &lt;a href="http://en.wikipedia.org/wiki/Law_of_Demeter"&gt;Law of Demeter&lt;/a&gt;.&amp;nbsp; The worst thing about Law of Demeter is that it has the word &amp;ldquo;Law&amp;rdquo; in it.&amp;nbsp; Like all of the SOLID principles, it should be considered a rule of thumb and your experience and knowledge of the domain should tell you when it it appropriate.&amp;nbsp; However, I would consider staying consistent with this principles (as with all of the others) the starting point and transgress only under special circumstances.&lt;/p&gt;
&lt;p&gt;If you haven&amp;rsquo;t heard of Demeter, the formal definition is that methods of a given class should only access:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Fields and Methods on the object.&lt;/li&gt;
&lt;li&gt;Any object created within the method.&lt;/li&gt;
&lt;li&gt;Any direct properties or methods of an argument to the method&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;By following Demeter, you have stronger encapsulation in your objects.&amp;nbsp; This will lead to fewer coupling points in your application and thereby lowering coupling in your system.&amp;nbsp; When you do violate this principle it is easy to get into the situation where a change in one part of system has repercussions in other parts that were not touched for a specific release.&amp;nbsp; That&amp;rsquo;s when your day after release becomes a nightmare of chasing down bugs in production you can&amp;rsquo;t explain.&lt;/p&gt;
&lt;p&gt;Recently I was was brought on to a very large application that has been in development for over a year.&amp;nbsp; When pairing with one the devs on a new feature, the implementation he proposed broke Demeter in several places, accessing child properties and methods a few levels deep.&amp;nbsp; When I brought this to his attention and explained to him that if you&amp;rsquo;re absolutely sure the object in question will always be created with the Properties in question, then you can considerate an allowable break of the rule.&lt;/p&gt;
&lt;p&gt;The developer I was partnering did not think it was possible to construct the object in which this violation would ever cause a problem.&amp;nbsp; He&amp;rsquo;s a smart guy and I have no reason to doubt him, but as the title of of this post states, change is the one true constant.&amp;nbsp; We know that requirements change over time.&amp;nbsp; We also know that end users are very creative in using applications for solving problems they are not designed for.&lt;/p&gt;
&lt;p&gt;Staying consistent with Demeter is my default way of developing new features.&amp;nbsp; Even if I think the chances of getting into an invalid state are infinitesimal, I still try to stay consistent with this principle.&amp;nbsp; It gives me greater flexibility to change the system as necessary and keeps my dependencies to getting to &amp;ldquo;sticky&amp;rdquo;, where I have to worry about who is accessing a property inappropriately&amp;nbsp; when it is time to change them.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Demeter+Helps+You+Fend+Off+the+One+True+Constant%3a+Change&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f07%2f20%2fdemeter-helps-you-fend-off-the-one-true-constant-change.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f07%2f20%2fdemeter-helps-you-fend-off-the-one-true-constant-change.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=23095" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/SOLID/default.aspx">SOLID</category><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/Law+of+Demeter/default.aspx">Law of Demeter</category><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/Software+Design/default.aspx">Software Design</category></item><item><title>Giving Your MVC Views an Identity</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/07/15/giving-your-mvc-views-an-identity.aspx</link><pubDate>Wed, 15 Jul 2009 05:01:00 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:22952</guid><dc:creator>jcteague</dc:creator><slash:comments>14</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=22952</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/07/15/giving-your-mvc-views-an-identity.aspx#comments</comments><description>&lt;p&gt;One of the great CSS tips I got from &lt;a href="http://bit.ly/19HYXY"&gt;Zen of CSS&lt;/a&gt; was to put an id on the body tag of your html pages.&amp;nbsp; This makes it really easy to use one CSS file for your entire site (a optimization trick) and allow you to target elements on specific page easily without creating a lot of unnecessary content wrappers or bogey class names.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;It is also very simple thing to do on MVC sites. Using the convention of Controller+Action give an easy identifier (if you&amp;rsquo;re using areas or something else you will need to tweak this a little).&amp;nbsp; This simple extension method does all the work for you.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="padding:5px;width:859px;display:block;float:none;margin-left:auto;margin-right:auto;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:17da7cd8-2f2e-4611-a865-e3de7a192786" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border:#000080 1px solid;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt;
&lt;div style="background-color:#ffffff;max-height:auto;overflow:scroll;padding:2px 5px;white-space:nowrap;"&gt;
&lt;p&gt;  &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;MasterPageExtensions&lt;/span&gt;&lt;br /&gt; &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;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; BuildPageIdentifier(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ViewMasterPage&lt;/span&gt; masterPage,&amp;nbsp;&amp;nbsp;&lt;span style="color:#2b91af;"&gt;ViewContext&lt;/span&gt; context)&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&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;&lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515;"&gt;&amp;quot;{0}-{1}&amp;quot;&lt;/span&gt;, context.RouteData.Values[&lt;span style="color:#a31515;"&gt;&amp;quot;controller&amp;quot;&lt;/span&gt;],context.RouteData.Values[&lt;span style="color:#a31515;"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;]);&lt;br /&gt; &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;\ &lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; Now just add this to your MasterPage.   &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="padding:5px;width:859px;display:block;float:none;margin-left:auto;margin-right:auto;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f7340f35-7c9d-4454-a185-99329ec2b3a2" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border:#000080 1px solid;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt;
&lt;div style="background-color:#ffffff;max-height:auto;overflow:scroll;padding:2px 5px;white-space:nowrap;"&gt;
&lt;p&gt;  &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;body&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;id&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;&lt;span&gt;= this.BuildPageIdentifier(this.ViewContext)&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;quot;&amp;gt;&lt;br /&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It will create html that looks like this.&lt;/p&gt;
&lt;p&gt; &amp;lt;body id=&amp;rdquo;Resident-Edit&amp;rdquo;&amp;gt;&lt;/p&gt;
&lt;p&gt;Now you can write CSS like this to target specific pages on your site.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="padding:5px;width:859px;display:block;float:none;margin-left:auto;margin-right:auto;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f14e6002-538d-4bb6-8593-b9b441b71899" class="wlWriterEditableSmartContent"&gt;
&lt;div style="border:#000080 1px solid;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt;
&lt;div style="background-color:#ffffff;max-height:300px;overflow:scroll;padding:2px 5px;white-space:nowrap;"&gt;
&lt;p&gt;  &lt;span style="color:#a31515;"&gt;#Resident-Edit&lt;/span&gt; &lt;span style="color:#a31515;"&gt;#VolumeLevel&lt;/span&gt; { &lt;span style="color:#ff0000;"&gt;display&lt;/span&gt;:&lt;span style="color:#0000ff;"&gt;block&lt;/span&gt;; &lt;span style="color:#ff0000;"&gt;margin-bottom&lt;/span&gt;:&lt;span style="color:#0000ff;"&gt;.8em&lt;/span&gt;; }
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Giving+Your+MVC+Views+an+Identity&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f07%2f15%2fgiving-your-mvc-views-an-identity.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f07%2f15%2fgiving-your-mvc-views-an-identity.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=22952" width="1" height="1"&gt;</description><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/MVC/default.aspx">MVC</category><category domain="http://www.lostechies.com/blogs/johnteague/archive/tags/CSS/default.aspx">CSS</category></item><item><title>Programming Basics: The for loop can do more than increment an integer</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/06/12/programming-basics-the-for-loop-can-do-more-than-increment-an-integer.aspx</link><pubDate>Fri, 12 Jun 2009 18:50:00 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:21861</guid><dc:creator>jcteague</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=21861</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/06/12/programming-basics-the-for-loop-can-do-more-than-increment-an-integer.aspx#comments</comments><description>&lt;p&gt;This is one of those small things that is easy to forget.&amp;nbsp; Usually when we use a for loop, we&amp;#39;ll just incrment over an integer so that we can get a specific item out of some iteration.&amp;nbsp; But you can do much more than that.&amp;nbsp; My current project has a complicated scheduling component and I&amp;#39;m often working with a range of dates.&amp;nbsp; I often need to do something with the days between two dates.&amp;nbsp; I created a TimePeriod class that is created with a start and end date.&lt;/p&gt;
&lt;p&gt;public class TimePeriod&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; private readonly DateTime _start;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private readonly DateTime _end;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public TimePeriod(DateTime start, DateTime end)&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; _start = start;&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; _end = end;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Now what I need to do is iterate over all of the days that are between these two dates.&amp;nbsp; I was struggling with this for a while, trying get a clean implementation.&amp;nbsp; Then I remembered that the for loop could do this for me.&amp;nbsp; Instead of using the standard i++ of the loop action, I add a day to the iteration variable.&amp;nbsp; Now I can get every day between the start and end date.&lt;/p&gt;
&lt;p&gt;public IEnumerable&amp;lt;DateTime&amp;gt; DaysInPeriod()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(var d = _start; d &amp;lt;= _end; d = d.AddDays(1))&lt;br /&gt;&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; yield return d;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Once I had this in place, I was able to put on some more convenience methods to cut down on some repetitive tasks I was performing.&lt;/p&gt;
&lt;p&gt;public bool Contains(DateTime dateTime)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return DaysInPeriod().Contains(dateTime);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public bool ContainsTheDayOfWeek(DayOfWeek dayOfWeek)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return DaysInPeriod().Any(d =&amp;gt; d.DayOfWeek == dayOfWeek);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;This was nothing Earth shattering, but a real simple abstraction made my life a lot easier.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Programming+Basics%3a+The+for+loop+can+do+more+than+increment+an+integer&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f06%2f12%2fprogramming-basics-the-for-loop-can-do-more-than-increment-an-integer.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f06%2f12%2fprogramming-basics-the-for-loop-can-do-more-than-increment-an-integer.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=21861" width="1" height="1"&gt;</description></item><item><title>Ruby and Rake as an executable</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/06/10/ruby-and-rake-as-an-executable.aspx</link><pubDate>Wed, 10 Jun 2009 20:05:00 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:21744</guid><dc:creator>jcteague</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=21744</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/06/10/ruby-and-rake-as-an-executable.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;ve been trying for months to get my partner in &lt;a href="http://www.nextleveltechnology.com"&gt;crime&lt;/a&gt;,&lt;a href="http://www.stephenbalkum.com"&gt; Stephen Balkum&lt;/a&gt;, to switch to Rake as our default build system.&amp;nbsp; We&amp;#39;ve been using Nant FOREVER and while it works, I really hate writing Nant scripts.&lt;/p&gt;
&lt;p&gt;The problem Stephen had with going to Rake where twofold.&amp;nbsp; One, we&amp;#39;re still doing (mostly) .Net apps, so the only thing we&amp;#39;d use Ruby for right now is Rake (hopefully that will change soon too).&amp;nbsp; And Ruby is a pretty big installation if you&amp;#39;re only building .Net projects with Rake.&lt;/p&gt;
&lt;p&gt;The other, more important, more problem is that we like to have completely self-contained projects.&amp;nbsp; So when a new dev comes online all they have to do is checkout from source control, click build.bat and you are ready to go.&amp;nbsp; You simply can&amp;#39;t do that with Ruby and Rake.&amp;nbsp; You must install Ruby and then get all of the gems necessary to run Rake.&lt;/p&gt;
&lt;p&gt;Well, Stephen found a way around all of this.&amp;nbsp; He has encapsulated Ruby, Rake, and all dependencies into a single 3mb executable.&amp;nbsp; Now it can be checked in and passed around like any other required tool.&lt;/p&gt;
&lt;p&gt;You can read more about it &lt;a href="http://www.stephenbalkum.com/archive/2009/06/09/when-all-you-need-is-a-rake.aspx"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Ruby+and+Rake+as+an+executable&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f06%2f10%2fruby-and-rake-as-an-executable.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f06%2f10%2fruby-and-rake-as-an-executable.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=21744" width="1" height="1"&gt;</description></item><item><title>Austin Code Camp Schedule</title><link>http://www.lostechies.com/blogs/johnteague/archive/2009/05/24/austin-code-camp-schedule.aspx</link><pubDate>Sun, 24 May 2009 20:39:00 GMT</pubDate><guid isPermaLink="false">ded273ab-9e87-4979-8222-e4e2e46f1b46:21207</guid><dc:creator>jcteague</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://www.lostechies.com/blogs/johnteague/rsscomments.aspx?PostID=21207</wfw:commentRss><comments>http://www.lostechies.com/blogs/johnteague/archive/2009/05/24/austin-code-camp-schedule.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.lostechies.com/blogs/hex/archive/2009/05/16/austin-code-camp-sessions-voting-results.aspx"&gt;Several&lt;/a&gt; &lt;a href="http://www.lostechies.com/blogs/chad_myers/archive/2009/05/17/austin-codecamp-09-quite-possibly-better-than-bacon.aspx"&gt;people&lt;/a&gt; &lt;a href="http://devlicious.com/blogs/anne_epstein/archive/2009/05/17/austin-code-camp-2009.aspx"&gt;have&lt;/a&gt; already mentioned some of the sessions at this year&amp;#39;s Austin Code Camp. We&amp;#39;ve&lt;a title="Austin Code Camp 09" href="http://www.adnug.org/austincodecamp09"&gt; posted the schedule&lt;/a&gt; for people to view.&amp;nbsp; We may move some around depending on how the &lt;a title="Vote for sessions" href="http://www.adnug.org/AustinCodeCamp09/Proposal/List"&gt;voting&lt;/a&gt; goes to make sure there is adequate space for each session.&amp;nbsp; So be sure and check again at the conference.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m really excited about this year&amp;#39;s line up.&amp;nbsp; I think it&amp;#39;s a good mix of nuts and bolts framework usage and best practices &amp;amp; improving your craft style presentations.&lt;/p&gt;
&lt;p&gt;As always, the Austin Code Camp is completely free, including food.&amp;nbsp; We are able to do this by the awesome presenters who volunteer their time deliver this information and to our sponosors who help with actual expenses.&lt;/p&gt;
&lt;p&gt;If you haven&amp;#39;t registered yet, please hurry up and do so. We want to make sure we order enough food for everyone.&lt;/p&gt;
&lt;p&gt;I hope to see your there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?title=Austin+Code+Camp+Schedule&amp;url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f05%2f24%2faustin-code-camp-schedule.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.lostechies.com%2fblogs%2fjohnteague%2farchive%2f2009%2f05%2f24%2faustin-code-camp-schedule.aspx" border="0" alt="Kick It on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://www.lostechies.com/aggbug.aspx?PostID=21207" width="1" height="1"&gt;</description></item></channel></rss>
