﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com/blog/</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2012 (c) 2012</copyright><ttl>60</ttl><item><title>RavenDB training: The euro tour</title><description>&lt;p&gt;We are planning of doing a lot of training on RavenDB, and I wanted to make sure that everyone is aware of it.&lt;/p&gt; &lt;p&gt;Next week , we have a public event in London. Where Itamar will explain all about indexing:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://skillsmatter.com/podcast/open-source-dot-net/ravendb/js-3392"&gt;RavenDB Indexes explained (public event) - Feb 28, London, UK&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Then there is the full 2 days workshop about RavenDB, here is the current schedule for the next few months.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://skillsmatter.com/course/open-source-dot-net/ayende-rahiens-ravendb-workshop"&gt;RavenDB Training with Itamar Syn-Hershko - Feb 28 - 29, London, UK&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.cornerstone.se/Web/Templates/CoursePage.aspx?id=2513&amp;amp;course=COUR2012012314201105395937&amp;amp;epslanguage=SV"&gt;RavenDB Workshop - Ayende Rahien - 21 - 23 May, Stockholm, Sweden&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.ndcoslo.com/Workshop/ravendb"&gt;The RavenDB Workshop Part I &amp;amp; II - Itamar Syn-Hershko - June 4th &amp;amp; 5th, Oslo, Norway&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;There is also going to be a course in the states around August, probably New York again and maybe around July in Berlin.&lt;/p&gt;</description><link>http://ayende.com/blog/154849/ravendb-training-the-euro-tour?key=c32bae45-21a9-4475-8b36-a070aacbff53</link><guid>http://ayende.com/blog/154849/ravendb-training-the-euro-tour?key=c32bae45-21a9-4475-8b36-a070aacbff53</guid><pubDate>Wed, 22 Feb 2012 10:00:00 GMT</pubDate></item><item><title>Limit your abstractions: And how do you handle testing?</title><description>&lt;p&gt;&lt;img style="display: inline; float: right" align="right" src="http://farm6.staticflickr.com/5086/5267223336_7e10f6f3c8_m.jpg"&gt;On my previous post, I explained about the value of pushing as much as possible to the infrastructure, and then show some code that showed how to do so. First, let us look at the business level code:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;[AcceptVerbs(HttpVerbs.Post)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Register(&lt;span class="kwrd"&gt;string&lt;/span&gt; originUnlocode, &lt;span class="kwrd"&gt;string&lt;/span&gt; destinationUnlocode, DateTime arrivalDeadline)
{
    var trackingId = &lt;font style="background-color: #ffff00"&gt;ExecuteCommand&lt;/font&gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; RegisterCargo
    {
        OriginCode = originUnlocode,
        DestinationCode = destinationUnlocode,
        ArrivalDeadline = arrivalDeadline
    });

    &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(ShowActionName, &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteValueDictionary(&lt;span class="kwrd"&gt;new&lt;/span&gt; { trackingId }));
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; RegisterCargo : Command&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute()
    {
        var origin = Session.Load&amp;lt;Location&amp;gt;(OriginCode);
        var destination = Session.Load&amp;lt;Location&amp;gt;(DestinationCode);

        var trackingId = Query(&lt;span class="kwrd"&gt;new&lt;/span&gt; NextTrackingIdQuery());

        var routeSpecification = &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteSpecification(origin, destination, ArrivalDeadline);
        var cargo = &lt;span class="kwrd"&gt;new&lt;/span&gt; Cargo(trackingId, routeSpecification);
        Session.Save(cargo);

        Result = trackingId;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; OriginCode { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; DestinationCode { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; DateTime ArrivalDeadline { get; set; }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;And the infrastructure code, now:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; &lt;font style="background-color: #ffff00"&gt;Default_&lt;/font&gt;&lt;font style="background-color: #ffff00"&gt;ExecuteCommand&lt;/font&gt;(Command cmd)
{
    cmd.Session = Session;
    cmd.Execute();
}

&lt;span class="kwrd"&gt;protected&lt;/span&gt; TResult &lt;font style="background-color: #ffff00"&gt;Default_ExecuteCommand&lt;/font&gt;&amp;lt;TResult&amp;gt;(Command&amp;lt;TResult&amp;gt; cmd)
{
    ExecuteCommand((Command) cmd);
    &lt;span class="kwrd"&gt;return&lt;/span&gt; cmd.Result;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;You might have noticed a problem in the way we are named things, the names on the action and the infrastructure code do not match. What is going on?&lt;/p&gt;
&lt;p&gt;Well, the answer is quite simple. Let us look at how our controller looks like ( at least, the important parts ):&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AbstractController : Controller
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ISession Session;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Action&amp;lt;Command&amp;gt; AlternativeExecuteCommand { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Func&amp;lt;Command, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; AlternativeExecuteCommandWithResult { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ExecuteCommand(Command cmd)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (AlternativeExecuteCommand!= &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            AlternativeExecuteCommand(cmd);
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
            Default_ExecuteCommand(cmd);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; TResult ExecuteCommand&amp;lt;TResult&amp;gt;(Command&amp;lt;TResult&amp;gt; cmd)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (AlternativeExecuteCommandWithResult != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;return&lt;/span&gt; (TResult)AlternativeExecuteCommandWithResult(cmd);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; Default_ExecuteCommand(cmd);
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Default_ExecuteCommand(Command cmd)
    {
        cmd.Session = Session;
        cmd.Execute();
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; TResult Default_ExecuteCommand&amp;lt;TResult&amp;gt;(Command&amp;lt;TResult&amp;gt; cmd)
    {
        ExecuteCommand((Command)cmd);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; cmd.Result;
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;What?! You do mocking by hand and inject them like that? That is horrible! It is much easier to use a mocking framework and ….&lt;/p&gt;
&lt;p&gt;Yes, it would be, if I was trying to mocking different things all the time. But given that I have &lt;em&gt;very &lt;/em&gt;few abstractions, it make sense to not only build this sort of infrastructure, but to also build infrastructure for those things _in the tests_.&lt;/p&gt;
&lt;p&gt;For example, let us write the test for the action:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;[Fact]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WillRegisterCargo()
{
  ExecuteAction&amp;lt;CargoAdminController&amp;gt;( c=&amp;gt; c.Register(&lt;span class="str"&gt;"US"&lt;/span&gt;, &lt;span class="str"&gt;"UK"&lt;/span&gt;, DateTime.Today) );
  
  Assert.IsType&amp;lt;RegisterCargo&amp;gt;( &lt;span class="kwrd"&gt;this&lt;/span&gt;.ExecutedCommands[0] );
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img style="display: inline; float: right" alt="Lego-mob 2" align="right" src="http://farm6.staticflickr.com/5249/5266605975_5d1f98d658_m.jpg"&gt;The ExecuteAction method belongs to the &lt;em&gt;test infrastructure&lt;/em&gt;, and it setups the controller to be run under the test scenario. Which allows me to &lt;em&gt;not &lt;/em&gt;execute the command, but to actually get it.&lt;/p&gt;
&lt;p&gt;From there, it is very easy to get to things like:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;[Fact]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WillCreateNewCargoWithNewTrackingId()
{
  SetupQueryResponse&amp;lt;NextTrackingIdQuery&amp;gt;(&lt;span class="str"&gt;"abc"&lt;/span&gt;);
  ExecuteCommand&amp;lt;RegisterCargo&amp;gt;( &lt;span class="kwrd"&gt;new&lt;/span&gt; RegisterCargo
  {
    OriginCode = &lt;span class="str"&gt;"US"&lt;/span&gt;,
    DestinationCode= &lt;span class="str"&gt;"UK"&lt;/span&gt;,
    ArrivalDeadline = DateTime.Today
  });
  
  var cargo = Session.Load&amp;lt;Cargo&amp;gt;(&lt;span class="str"&gt;"cargos/1"&lt;/span&gt;);
  Assert.Equal(&lt;span class="str"&gt;"abc"&lt;/span&gt;, cargo.TrackingId);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is important, because now what you are testing is the actual interaction. You don’t care about any of the actual dependencies, we just abstracted them out, but without creating ton of interfaces, abstractions on top of abstractions or any of that.&lt;/p&gt;
&lt;p&gt;In fact, we kept the number of abstractions to a minimum, and we can change pretty much every part of the system with very little fear of cascading change.&lt;/p&gt;
&lt;p&gt;We have similar lego pieces, all of them move together and interact with one another with complete freedom, and we don’t have to have a &lt;a href="http://discuss.joelonsoftware.com/default.asp?joel.3.219431"&gt;Abstract Factory Factory Façade Factory&lt;/a&gt;.&lt;/p&gt;</description><link>http://ayende.com/blog/154273/limit-your-abstractions-and-how-do-you-handle-testing?key=9d736120-389f-4c65-bdee-1bebc60cbd14</link><guid>http://ayende.com/blog/154273/limit-your-abstractions-and-how-do-you-handle-testing?key=9d736120-389f-4c65-bdee-1bebc60cbd14</guid><pubDate>Wed, 22 Feb 2012 07:49:00 GMT</pubDate></item><item><title>Limit your abstractions: The key is in the infrastructure&amp;hellip;</title><description>&lt;p&gt;In my previous post, I discussed actual refactoring to reduce abstraction, and I showed two very interesting methods, Query() and ExecuteCommand(). Here is the code in question:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;[AcceptVerbs(HttpVerbs.Post)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Register(&lt;span class="kwrd"&gt;string&lt;/span&gt; originUnlocode, &lt;span class="kwrd"&gt;string&lt;/span&gt; destinationUnlocode, DateTime arrivalDeadline)
{
    var trackingId = &lt;font style="background-color: #ffff00"&gt;ExecuteCommand&lt;/font&gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; RegisterCargo
    {
        OriginCode = originUnlocode,
        DestinationCode = destinationUnlocode,
        ArrivalDeadline = arrivalDeadline
    });

    &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(ShowActionName, &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteValueDictionary(&lt;span class="kwrd"&gt;new&lt;/span&gt; { trackingId }));
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; RegisterCargo : Command&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute()
    {
        var origin = Session.Load&amp;lt;Location&amp;gt;(OriginCode);
        var destination = Session.Load&amp;lt;Location&amp;gt;(DestinationCode);

        var trackingId = &lt;font style="background-color: #ffff00"&gt;Query&lt;/font&gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; NextTrackingIdQuery());

        var routeSpecification = &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteSpecification(origin, destination, ArrivalDeadline);
        var cargo = &lt;span class="kwrd"&gt;new&lt;/span&gt; Cargo(trackingId, routeSpecification);
        Session.Save(cargo);

        Result = trackingId;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; OriginCode { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; DestinationCode { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; DateTime ArrivalDeadline { get; set; }
}
&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;What are they so important? Mostly because those methods [and similar, like Raise(event) and ExecuteLater(task)] are actually the back bone of the application. They are the infrastructure on top of which everything rests.&lt;/p&gt;
&lt;p&gt;Those methods basically accept an argument (and optionally return a value). Their responsibility are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Setup the given argument so it can run.&lt;/li&gt;
&lt;li&gt;Execute it.&lt;/li&gt;
&lt;li&gt;Return the result (if there is one).&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Here is an example showing how to implement ExecuteCommand:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Default_ExecuteCommand(Command cmd)
{
    cmd.Session = Session;
    cmd.Execute();
}

&lt;span class="kwrd"&gt;protected&lt;/span&gt; TResult Default_ExecuteCommand&amp;lt;TResult&amp;gt;(Command&amp;lt;TResult&amp;gt; cmd)
{
    ExecuteCommand((Command) cmd);
    &lt;span class="kwrd"&gt;return&lt;/span&gt; cmd.Result;
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;I have code very much like that in &lt;em&gt;production&lt;/em&gt;, because I &lt;em&gt;know&lt;/em&gt; that in this system, there are actually only one or two dependencies that a command may want.&lt;/p&gt;
&lt;p&gt;There are very few other dependencies, because of the limited number of abstractions that we have. This makes things very simple to write and work with.&lt;/p&gt;
&lt;p&gt;Because we abstract away any dependency management, and because we allow only very small number of abstractions, this works very well. The amount of complexity that you have is way down, code reviewing this is very easy, because there isn’t much &lt;em&gt;to &lt;/em&gt;review, and it all follows the same structure. The implementation of the rest are pretty much the same thing.&lt;/p&gt;
&lt;p&gt;There is just one thing left to discuss, because it kept showing up on the comments for the other posts. How do you handle testing?&lt;/p&gt;</description><link>http://ayende.com/blog/154241/limit-your-abstractions-the-key-is-in-the-infrastructurehellip?key=b8321fd5-9738-4139-a8a4-f30f2f257692</link><guid>http://ayende.com/blog/154241/limit-your-abstractions-the-key-is-in-the-infrastructurehellip?key=b8321fd5-9738-4139-a8a4-f30f2f257692</guid><pubDate>Tue, 21 Feb 2012 07:28:00 GMT</pubDate></item><item><title>Limit your abstractions: Refactoring toward reduced abstractions</title><description>&lt;p&gt;So in my previous post I spoke about this code and the complexity behind it:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoAdminController : BaseController
{
  [AcceptVerbs(HttpVerbs.Post)]
  &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Register(
      [ModelBinder(&lt;span class="kwrd"&gt;typeof&lt;/span&gt; (RegistrationCommandBinder))] RegistrationCommand registrationCommand)
  {
      DateTime arrivalDeadlineDateTime = DateTime.ParseExact(registrationCommand.ArrivalDeadline, RegisterDateFormat,
                                                             CultureInfo.InvariantCulture);

      &lt;span class="kwrd"&gt;string&lt;/span&gt; trackingId = BookingServiceFacade.BookNewCargo(
          registrationCommand.OriginUnlocode, registrationCommand.DestinationUnlocode, arrivalDeadlineDateTime
          );

      &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(ShowActionName, &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteValueDictionary(&lt;span class="kwrd"&gt;new&lt;/span&gt; {trackingId}));
  }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;In this post, I intend to show how we can refactor things. I am going to do that by flattening the architecture, removing useless abstractions and creating a simpler, easier to work with system.&lt;/p&gt;
&lt;p&gt;The first thing to do is to refactor the method signature:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;[AcceptVerbs(HttpVerbs.Post)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Register(&lt;span class="kwrd"&gt;string&lt;/span&gt; originUnlocode, &lt;span class="kwrd"&gt;string&lt;/span&gt; destinationUnlocode, DateTime arrivalDeadline)&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Those are three parameters that we need, there is no need to create a model binder, custom command, etc just for this. For that matter, if you already have a model binder, why on earth do you store the date as a string, and not a date time. The framework is quite happy to do the conversion for me, and if it can’t, I can extend the &lt;em&gt;infrastructure to do so&lt;/em&gt;. I don’t need to patch this action with date parsing code.&lt;/p&gt;
&lt;p&gt;Next, we have this notion of booking a new cargo, looking at the service, that looks like:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; BookNewCargo(&lt;span class="kwrd"&gt;string&lt;/span&gt; origin, &lt;span class="kwrd"&gt;string&lt;/span&gt; destination, DateTime arrivalDeadline)
{
    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        TrackingId trackingId = BookingService.BookNewCargo(
            &lt;span class="kwrd"&gt;new&lt;/span&gt; UnLocode(origin),
            &lt;span class="kwrd"&gt;new&lt;/span&gt; UnLocode(destination),
            arrivalDeadline
            );
        &lt;span class="kwrd"&gt;return&lt;/span&gt; trackingId.IdString;
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception exception)
    {
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NDDDRemoteBookingException(exception.Message);
    }
}
&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;The error handling alone sets my teeth on edge. Also, note that we have a complex type for TrackingId, which contains just a string (there is a lot of code there for IValueObject&amp;lt;T&amp;gt;, comparison, etc), all of which basically go away if you use an actual string. The same is true for UnLocode (UN Location Code, I assume), but at least this one has some validation code in it.&lt;/p&gt;
&lt;p&gt;Then there is the lovely forwarding call, which translate to:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; TrackingId BookNewCargo(UnLocode originUnLocode,
                               UnLocode destinationUnLocode,
                               DateTime arrivalDeadline)
{
    &lt;span class="kwrd"&gt;using&lt;/span&gt; (var transactionScope = &lt;span class="kwrd"&gt;new&lt;/span&gt; TransactionScope())
    {
        TrackingId trackingId = cargoRepository.NextTrackingId();
        Location origin = locationRepository.Find(originUnLocode);
        Location destination = locationRepository.Find(destinationUnLocode);

        Cargo cargo = CargoFactory.NewCargo(trackingId, origin, destination, arrivalDeadline);

        cargoRepository.Store(cargo);
        logger.Info(&lt;span class="str"&gt;"Booked new cargo with tracking id "&lt;/span&gt; + cargo.TrackingId);

        transactionScope.Complete();
        &lt;span class="kwrd"&gt;return&lt;/span&gt; cargo.TrackingId;
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;And now we got somewhere, we actually have something there that is actually meaningful. I’ll skip going deeper, I am pretty sure that you can understand what is going on. &lt;/p&gt;
&lt;p&gt;From my point of view of the common abstractions in an application:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Controllers 
&lt;li&gt;Views 
&lt;li&gt;Entities 
&lt;li&gt;Commands 
&lt;li&gt;Tasks 
&lt;li&gt;Events 
&lt;li&gt;Queries&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Controllers are at the boundaries of the system, they orchestrate the entire system behavior. Note that I have no place for services or repositories in this list. That is quite intentional. Instead of going that route. &lt;/p&gt;
&lt;p&gt;Take a look at the code that I ended up with:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt; [AcceptVerbs(HttpVerbs.Post)]
 &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Register(&lt;span class="kwrd"&gt;string&lt;/span&gt; originUnlocode, &lt;span class="kwrd"&gt;string&lt;/span&gt; destinationUnlocode, DateTime arrivalDeadline)
 {
     var origin = Session.Load&amp;lt;Location&amp;gt;(originUnlocode);
     var destination = Session.Load&amp;lt;Location&amp;gt;(destinationUnlocode);

     var trackingId = Query(&lt;span class="kwrd"&gt;new&lt;/span&gt; NextTrackingIdQuery());

     var routeSpecification = &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteSpecification(origin, destination, arrivalDeadline);
     var cargo = &lt;span class="kwrd"&gt;new&lt;/span&gt; Cargo(trackingId, routeSpecification);
     Session.Store(cargo);

     &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(ShowActionName, &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteValueDictionary(&lt;span class="kwrd"&gt;new&lt;/span&gt; {trackingId}));
 }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;As you can see, the entire architecture was collapsed into a single method.&lt;/p&gt;
&lt;p&gt;And what kind of abstractions do we have here?&lt;/p&gt;
&lt;p&gt;Well, we have the usual things from MVC, Controller, Action, parameter binding. &lt;/p&gt;
&lt;p&gt;We have the session that we are using to load data by id, and to store the newly create cargo. &lt;/p&gt;
&lt;p&gt;And we have the notion of a query. Generating a new TrackingID is a query that happen on the database (actually implemented as a hilo sequence). That is something that is definitely not the responsibility of the controller action, so we moved it into a query. Note that we have the Query() method there. It is defined as:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; TResult Query&amp;lt;TResult&amp;gt;(Query&amp;lt;TResult&amp;gt; query)&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;And NextTrackingIdQuery is defined as:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; NextTrackingIdQuery : Query&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Pretty simple, overall. And I can hear the nitpickers climb over the fences, waving the pitchforks and torches. “What happen when you need to reuse this logic? It is not in the UI and …”&lt;/p&gt;
&lt;p&gt;There are a couple of things to note here. &lt;/p&gt;
&lt;p&gt;First, there &lt;em&gt;isn’t &lt;/em&gt;anywhere else that needs to book a cargo. And saying “and what happen when…” flies right into a wall of people shouting YAGNI.&lt;/p&gt;
&lt;p&gt;Second, let us assume that there &lt;em&gt;is&lt;/em&gt; such a need, to reuse the booking cargo scenario. How would we approach this?&lt;/p&gt;
&lt;p&gt;Well, we can encapsulate the logic for the controller inside a Command. Which gives us:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;[AcceptVerbs(HttpVerbs.Post)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Register(&lt;span class="kwrd"&gt;string&lt;/span&gt; originUnlocode, &lt;span class="kwrd"&gt;string&lt;/span&gt; destinationUnlocode, DateTime arrivalDeadline)
{
    var trackingId = ExecuteCommand(&lt;span class="kwrd"&gt;new&lt;/span&gt; RegisterCargo
    {
        OriginCode = originUnlocode,
        DestinationCode = destinationUnlocode,
        ArrivalDeadline = arrivalDeadline
    });

    &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(ShowActionName, &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteValueDictionary(&lt;span class="kwrd"&gt;new&lt;/span&gt; { trackingId }));
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;And then we have the actual RegisterCargo command:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Command
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; IDocumentSession Session { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute();

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; TResult Query&amp;lt;TResult&amp;gt;(Query&amp;lt;TResult&amp;gt; query);
}
&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Command&amp;lt;T&amp;gt; : Command
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; T Result { get; &lt;span class="kwrd"&gt;protected&lt;/span&gt; set; }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; RegisterCargo : Command&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute()
    {
        var origin = Session.Load&amp;lt;Location&amp;gt;(OriginCode);
        var destination = Session.Load&amp;lt;Location&amp;gt;(DestinationCode);

        var trackingId = Query(&lt;span class="kwrd"&gt;new&lt;/span&gt; NextTrackingIdQuery());

        var routeSpecification = &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteSpecification(origin, destination, ArrivalDeadline);
        var cargo = &lt;span class="kwrd"&gt;new&lt;/span&gt; Cargo(trackingId, routeSpecification);
        Session.Save(cargo);

        Result = trackingId;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; OriginCode { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; DestinationCode { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; DateTime ArrivalDeadline { get; set; }
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Note that the Command class also have a way to execute queries, in fact, it is the exact same way that we use when we had the code in the controller. We just moved stuff around, not really made any major change, but we can easily start using the same functionality in another location.&lt;/p&gt;
&lt;p&gt;I generally don’t like doing this because most functionality is &lt;em&gt;not&lt;/em&gt; reused, it is specific for a particular place and scenario, but I wanted to show how you can lift some part of the code and move it to a different location, otherwise people would complain about the “lack of reuse opportunities”.&lt;/p&gt;
&lt;p&gt;On my next post I am going to talk about the Query() and ExecuteCommand() methods, and why they are so important.&lt;/p&gt;</description><link>http://ayende.com/blog/154209/limit-your-abstractions-refactoring-toward-reduced-abstractions?key=af15e59a-985a-4bf2-a678-b25136153ed8</link><guid>http://ayende.com/blog/154209/limit-your-abstractions-refactoring-toward-reduced-abstractions?key=af15e59a-985a-4bf2-a678-b25136153ed8</guid><pubDate>Mon, 20 Feb 2012 07:02:00 GMT</pubDate></item><item><title>RavenHQ goes beta&amp;ndash;RavenDB reaches the cloud</title><description>&lt;p&gt;
	One of the things that we have been doing lately was providing solutions for cloud hosted RavenDB. I am very proud to announce the public beta phase of RavenHQ, a cloud based, fully managed RavenDB service.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/RavenHQ-goes-beta_F81/image_2.png"&gt;&lt;img alt="image" border="0" height="406" src="http://ayende.com/blog/Images/Windows-Live-Writer/RavenHQ-goes-beta_F81/image_thumb.png" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" width="383" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	Currently it is available on &lt;a href="https://appharbor.com/addons/ravenhq"&gt;AppHarbor&lt;/a&gt; only, and I must emphasis that this is &lt;em&gt;still a beta&lt;/em&gt;, so you might run into some road bumps, but we have a really good team working on this.&lt;/p&gt;
&lt;p&gt;
	Actually, here is an important detail, about this offering.&lt;/p&gt;
&lt;p&gt;
	Hibernating Rhinos (the company who is actually doing the development of RavenDB) is at heart a development / consulting company. We didn&amp;rsquo;t want to try to break apart something good, so we setup a new company dedicated for running RavenDB on the cloud, RavenHQ.&lt;/p&gt;
&lt;p&gt;
	Why do you care about this? Because it means that while the RavenDB development team is available for any problem that you might run into, RavenHQ is actually stuffed by people whose job is merely to make sure that all your databases are humming along nicely, and not a developer who is 15% of watching what is going on in that server somewhere on the cloud.&lt;/p&gt;
&lt;p&gt;
	I collaborated in RavenHQ with Jonathan Matheus (NSeviceBus Committer and an all around cool guy) to create something that I feel will be really awesome.&lt;/p&gt;
&lt;p&gt;
	As I said before, we are currently offering RavenHQ on App Harbor only, but we will soon open it for general registration. In the meantime, this is &lt;em&gt;called beta for a reason&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;
	It is &lt;strong&gt;hard&lt;/strong&gt; to test cloud based stuff in a lab, so after we have made sure that everything works, the next step is to see if you can break it. I am assuming the worse at that you &lt;em&gt;will&lt;/em&gt; manage to break it in all sorts of creative ways. Please give us a short amount of grace period to make sure that we can match our internal workings to how people are actually using us.&lt;/p&gt;
&lt;p&gt;
	Have an awesome weekend!&lt;/p&gt;
</description><link>http://ayende.com/blog/154785/ravenhq-goes-betandash-ravendb-reaches-the-cloud?key=931c442f-ab5e-4eed-86ba-0d9f1b7c21d8</link><guid>http://ayende.com/blog/154785/ravenhq-goes-betandash-ravendb-reaches-the-cloud?key=931c442f-ab5e-4eed-86ba-0d9f1b7c21d8</guid><pubDate>Sat, 18 Feb 2012 01:20:00 GMT</pubDate></item><item><title>RavenDB: Index Boosting</title><description>&lt;p&gt;Recently we added a really nice feature, boosting the results while indexing. &lt;/p&gt; &lt;p&gt;Boosting is a way to give documents or attributes in a document weights. Attribute level boosting is a way to tell RavenDB that a certain&amp;nbsp; attribute in a document is more important than the others, so it will show up higher in queries when other properties are involved in a query. A document level boosting means that a certain document is more important than another (when using multi maps). &lt;p&gt;Let us see a few examples where this is happening. The simplest scenario is when we have a multi field search, and we want one of the fields to be the more important one. For example, we decided that when you make a search for first name and last name, a match on the first name has higher relevance than a match on the last name. We can define this requirement with the following index:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Users_ByName : AbstractIndexCreationTask&amp;lt;User&amp;gt;
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Users_ByName()
    {
        Map = users =&amp;gt; from user &lt;span class="kwrd"&gt;in&lt;/span&gt; users
                       select &lt;span class="kwrd"&gt;new&lt;/span&gt;
                       {
                           FirstName = user.FirstName&lt;font style="background-color: #ffff00"&gt;.Boost(3),
&lt;/font&gt;                           user.LastName
                       };
    }
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;And we can query the index using:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;var matches = session.Query&amp;lt;User,UsersByName&amp;gt;()
      .Where(x=&amp;gt;x.FirstName == &lt;span class="str"&gt;"Ayende"&lt;/span&gt; || x.LastName == &lt;span class="str"&gt;"Eini"&lt;/span&gt;)
      .ToList()&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Assuming that we have a user with the first name “Ayende” and another user with the last name “Eini”, this will find &lt;em&gt;both &lt;/em&gt;of them, but will rank the user with the name “Ayende” first.&lt;/p&gt;
&lt;p&gt;Let us see another variant, we have a multi map index for users and accounts, both are searchable by name, but we want to ensure that accounts are more important than users. We can do that using the following index:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; UsersAndAccounts : AbstractMultiMapIndexCreationTask
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; UsersAndAccounts()
    {
        AddMap&amp;lt;User&amp;gt;(users =&amp;gt;
                     from user &lt;span class="kwrd"&gt;in&lt;/span&gt; users
                     select &lt;span class="kwrd"&gt;new&lt;/span&gt; {Name = user.FirstName}
            );
        AddMap&amp;lt;Account&amp;gt;(accounts =&amp;gt;
                        from account &lt;span class="kwrd"&gt;in&lt;/span&gt; accounts
                        select &lt;span class="kwrd"&gt;new&lt;/span&gt; {account.Name}&lt;font style="background-color: #ffff00"&gt;.Boost(3)&lt;/font&gt;
            );
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;If we have query that has matches for users and accounts, this will make sure that the account comes first.&lt;/p&gt;
&lt;p&gt;And finally, a really interesting use case is that based on the entity itself, you decide to rank it higher. For example, we want to rank customers that ordered a lot from us higher than other customers. We can do that using the following index:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Accounts_Search : AbstractIndexCreationTask&amp;lt;Account&amp;gt;
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Accounts_Search()
    {
        Map = accounts =&amp;gt;
              from account &lt;span class="kwrd"&gt;in&lt;/span&gt; accounts
              select &lt;span class="kwrd"&gt;new&lt;/span&gt;
              {
                  account.Name
              }&lt;font style="background-color: #ffff00"&gt;.Boost(account.TotalIncome &amp;gt; 10000 ? 3 : 1)&lt;/font&gt;;
    }
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;This way, we get the more important customers first. And this is really one of those things that brings up the polish in the system, the things that makes the users sit up and take notice.&lt;/p&gt;</description><link>http://ayende.com/blog/153185/ravendb-index-boosting?key=edb9508e-8ce3-4eee-99a8-af01c816ad4f</link><guid>http://ayende.com/blog/153185/ravendb-index-boosting?key=edb9508e-8ce3-4eee-99a8-af01c816ad4f</guid><pubDate>Fri, 17 Feb 2012 10:00:00 GMT</pubDate></item><item><title>Limit your abstractions: So what is the whole big deal about?</title><description>&lt;p&gt;
	When I started out, I pointed out that I truly dislike this type of architecture:&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-So-what-is-the-w_DAD0/image_2.png"&gt;&lt;img alt="image" border="0" height="605" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-So-what-is-the-w_DAD0/image_thumb.png" style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" width="1123" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	And I said that I much rather an architecture that has a far more limited set of abstractions, and I gave this example:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		Controllers&lt;/li&gt;
	&lt;li&gt;
		Views&lt;/li&gt;
	&lt;li&gt;
		Entities&lt;/li&gt;
	&lt;li&gt;
		Commands&lt;/li&gt;
	&lt;li&gt;
		Tasks&lt;/li&gt;
	&lt;li&gt;
		Events&lt;/li&gt;
	&lt;li&gt;
		Queries&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
	That is all nice in theory, but let us talk in practice, shall we? How do we actually write code that actually uses this model?&lt;/p&gt;
&lt;p&gt;
	Let us show some code that uses this type of code, this type, this is from the C# port of the same codebase, &lt;a href="http://code.google.com/p/ndddsample/"&gt;available here&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
	&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoAdminController : BaseController
{
  [AcceptVerbs(HttpVerbs.Post)]
  &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Register(
      [ModelBinder(&lt;span class="kwrd"&gt;typeof&lt;/span&gt; (RegistrationCommandBinder))] RegistrationCommand registrationCommand)
  {
      DateTime arrivalDeadlineDateTime = DateTime.ParseExact(registrationCommand.ArrivalDeadline, RegisterDateFormat,
                                                             CultureInfo.InvariantCulture);

      &lt;span class="kwrd"&gt;string&lt;/span&gt; trackingId = BookingServiceFacade.BookNewCargo(
          registrationCommand.OriginUnlocode, registrationCommand.DestinationUnlocode, arrivalDeadlineDateTime
          );

      &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(ShowActionName, &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteValueDictionary(&lt;span class="kwrd"&gt;new&lt;/span&gt; {trackingId}));
  }
}&lt;/pre&gt;
	&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }	&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	Does this looks good to you? Here is what is actually going on here.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-So-what-is-the-w_DAD0/image_4.png"&gt;&lt;img alt="image" border="0" height="480" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-So-what-is-the-w_DAD0/image_thumb_1.png" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" width="452" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	You can click on &lt;a href="http://ayende-temp.s3.amazonaws.com/Blog-posts-154177-Diagram.pdf"&gt;this link&lt;/a&gt; look at what is going in here (and I removed some stuff for clarity&amp;rsquo;s sake.&lt;/p&gt;
&lt;p&gt;
	This stuff is &lt;em&gt;complex&lt;/em&gt;, more to the point, it doesn&amp;rsquo;t read naturally, it is hard to make a change without modifying a lot of code. This is scary.&lt;/p&gt;
&lt;p&gt;
	We have a lot of abstractions here, services and repositories and facades and what not. (Mind, each of those thing is an &lt;em&gt;independent abstraction&lt;/em&gt;, not a common one.)&lt;/p&gt;
&lt;p&gt;
	In my next post, I&amp;rsquo;ll show how to refactor this to a much saner model.&lt;/p&gt;
&lt;!--EndFragment--&gt;</description><link>http://ayende.com/blog/154177/limit-your-abstractions-so-what-is-the-whole-big-deal-about?key=c6cb2083-42a3-4eb2-87b9-3ddcd9025f5a</link><guid>http://ayende.com/blog/154177/limit-your-abstractions-so-what-is-the-whole-big-deal-about?key=c6cb2083-42a3-4eb2-87b9-3ddcd9025f5a</guid><pubDate>Thu, 16 Feb 2012 09:10:00 GMT</pubDate></item><item><title>Limit your abstractions: All cookies looks the same to the cookie cutter</title><description>&lt;p&gt;&lt;img style="display: inline; float: right" align="right" src="http://www.thetoyzone.com/wp-content/uploads/2009/02/minifig_wall.jpg"&gt;&lt;/p&gt; &lt;p&gt;One of the major advantages of limiting the number of abstractions you have is that you end up with a lot less “infrastructure” code. This is in quote because a lot of the time I see this type of code doing things like this:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BookingServiceImpl : IBookingService  
{

  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; IList&amp;lt;Itinerary&amp;gt; RequestPossibleRoutesForCargo(TrackingId trackingId)
  {
    Cargo cargo = cargoRepository.Find(trackingId);

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
      &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Itinerary&amp;gt;();
    }

    &lt;span class="kwrd"&gt;return&lt;/span&gt; routingService.FetchRoutesForSpecification(cargo.routeSpecification());
  }
  
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;I don’t want to see stuff like that. Instead, I want to be able to go into any piece of code and figure out by what it &lt;em&gt;is&lt;/em&gt; what it must be &lt;em&gt;doing&lt;/em&gt;. All my code follow fairly similar patterns, and the only differences that I have are actual &lt;em&gt;business&lt;/em&gt; differences.&lt;/p&gt;
&lt;p&gt;Here is the list of common abstractions that I gave before, this time, I am going to go over each one and explain it. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Controllers – Stand at the edge of the system and manage interaction with the outside world. Can be MVC controllers, MVVM models, WCF Services. 
&lt;li&gt;Views&amp;nbsp; - The actual UI logic that is being executed. Can be MVC views, XAML, or real UI code (you know, that old WinForms stuff &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Dealing-with-lim_6374/wlEmoticon-smile_2.png"&gt;).
&lt;li&gt;Entities – Data that is being persisted. 
&lt;li&gt;Commands – A packaged command to do something that will execute immediately. (Usually invoked by controllers).
&lt;li&gt;Tasks – A packaged execution that will be execute at a later point in time (usually async), after the current operation have completed.
&lt;li&gt;Events – Something that happened in the system that is interesting and require action. Common place for business logic and interaction. 
&lt;li&gt;Queries – Packaged query to be executed immediately. Usually only fairly complex ones gets promoted to an actual query object.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;There might be a few others in your system, but for the most part, you would see those types of things over and over and over again.&lt;/p&gt;
&lt;p&gt;Oh, sure, you might have other things as well, but those should be &lt;em&gt;rare&lt;/em&gt;. If you need to display things in multiple currency interacting with a currency service is something that you would need to often, by all means, make it easy to do (how you do &lt;em&gt;that&lt;/em&gt; is usually not important), but the important thing to remember is that those sort of things are one off, and they should &lt;em&gt;remain&lt;/em&gt; one off, not the way you structure the entire app.&lt;/p&gt;
&lt;p&gt;The reason this is important is that once you have this common infrastructure and shape (for lack of a better word), you can start working in a very rapid pace, without being distracted, and making &lt;em&gt;changes&lt;/em&gt; becomes easy. All of your architecture is going through the same central pipes, shifting where they are going is easy to do. You don’t have to drag a rigid system made of a lot of small individual pieces, after all.&lt;!--EndFragment--&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/154145/limit-your-abstractions-all-cookies-looks-the-same-to-the-cookie-cutter?key=91727ff8-a817-4d05-978a-0b8a979f0b88</link><guid>http://ayende.com/blog/154145/limit-your-abstractions-all-cookies-looks-the-same-to-the-cookie-cutter?key=91727ff8-a817-4d05-978a-0b8a979f0b88</guid><pubDate>Wed, 15 Feb 2012 07:22:00 GMT</pubDate></item><item><title>Limit your abstractions: Commands vs. Tasks, did you forget the workflow?</title><description>&lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit.-Tasks-did-you-forget-the-workflow_5CAE/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit.-Tasks-did-you-forget-the-workflow_5CAE/image_thumb.png" width="238" height="223"&gt;&lt;/a&gt;On my last post, I outlined the major abstractions that I tend to use in my applications.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Controllers  &lt;li&gt;Views  &lt;li&gt;Entities  &lt;li&gt;&lt;strike&gt;Commands &lt;/strike&gt; &lt;li&gt;Tasks  &lt;li&gt;Events  &lt;li&gt;Queries&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;I also said that I like Tasks much more than Commands and I’ll explain that in the future. When talking about tasks, I usually talk about something that is based on &lt;a href="https://github.com/ayende/RaccoonBlog/tree/master/HibernatingRhinos.Loci.Common/Tasks"&gt;this code&lt;/a&gt;. This give us the ability to write code such as this:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AssignCargoToRoute : BackgroundTask
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; Itinerary Itinerary { get;set; }
  TrackingId TrackingId { get;set; }

  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute()
  {
    
  }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;On the face of it, this is a &lt;em&gt;very&lt;/em&gt; &lt;em&gt;similar &lt;/em&gt;to what we have had before. So why am I so much in favor of tasks rather than commands?&lt;/p&gt;
&lt;p&gt;Put simply, the promises that they make are different.&amp;nbsp; A command will execute immediately, this is good when we are encapsulating common or complex piece of logic. We give it a meaningful name and move on with our lives.&lt;/p&gt;
&lt;p&gt;The problem is that in many cases, executing immediately is something that we &lt;em&gt;don’t &lt;/em&gt;want. Why is that?&lt;/p&gt;
&lt;p&gt;Well, what happen if this can take a while? What if this requires touching a remote resource (one that can’t take part of our transaction)? What happen if we want this to execute, but only if the entire operation have been successful? How do we handle errors? What happen when the scenario calls for a complex workflow? Can I partially succeed in what I am doing? Can you have a compensating action if some part fail? All of those scenarios basically boil down to “I don’t want to execute it now, I want the execution to be managed for me”.&lt;/p&gt;
&lt;p&gt;Thing about the scenario that we actually have here. We need to assign a cargo to a route. But what does that &lt;em&gt;means&lt;/em&gt;? In the trivial example, we do that by updating some data in our local database. But in real world scenario, something like that tends to be much more complex. We need to calculate shipping charges, check manifest, verify that we have all the proper permits, etc. All of that takes time, and usually collaboration with external systems. &lt;/p&gt;
&lt;p&gt;For the most part, I find that real world systems requires a lot more tasks than commands. Mostly because it is actually rare to have complex interaction inside your own system. If you do, you have to be cautious that you aren’t adding too much complexity. It is the external interactions that tends to makes life… interesting.&lt;/p&gt;
&lt;p&gt;This has implications on how we are building the system, because we don’t assume immediate execution and the temporal coupling that comes with it.&lt;/p&gt;</description><link>http://ayende.com/blog/154113/limit-your-abstractions-commands-vs-tasks-did-you-forget-the-workflow?key=7e476126-c7d0-4a63-b5d0-ed8e3fb5a0bc</link><guid>http://ayende.com/blog/154113/limit-your-abstractions-commands-vs-tasks-did-you-forget-the-workflow?key=7e476126-c7d0-4a63-b5d0-ed8e3fb5a0bc</guid><pubDate>Tue, 14 Feb 2012 07:35:00 GMT</pubDate></item><item><title>Limit your abstractions: You only get six to a dozen in the entire app</title><description>&lt;p&gt;
	Let us take a look at another part of the &lt;a href="http://dddsample.sourceforge.net/index.html"&gt;DDD sample application&lt;/a&gt;. This time, the booking service.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions_4CC1/image_2.png"&gt;&lt;img alt="image" border="0" height="180" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions_4CC1/image_thumb.png" style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" width="595" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	One thing that is really glaring at me is that we have a mix of both commands and queries in this interface. Also, just consider the name. It is a Booking service, but it doesn&amp;rsquo;t actually seem to have an actual meaning in the application itself. There is no entity named Booking, and except for the BookNewCargo, there is no mention of booking anywhere in the application.&lt;/p&gt;
&lt;p&gt;
	You know what, maybe there is logic in the RequestPossibleRoutesForCargo that is actually meaningful beyond a simple query. Such as charging the customer for the calculation, or reserving space on the route that we selected, etc.&lt;/p&gt;
&lt;p&gt;
	At any rate, I don&amp;rsquo;t like this service at all. In fact, any time that you have something that is called XyzService, you ought to suspect it.&amp;nbsp; Let me take this one step further. I don&amp;rsquo;t like that it is an interface, and I don&amp;rsquo;t like how it is composed. I don&amp;rsquo;t see it as an independent thing. Going further than that, I don&amp;rsquo;t really see a reason why we would need an interface here. You might have noticed what the title of this series is. I want to limit abstraction, and IBookingService is an abstraction, one that I don&amp;rsquo;t see any value in.&lt;/p&gt;
&lt;p&gt;
	In most applications, I like to have a &lt;em&gt;very&lt;/em&gt; small number of abstractions. Usually in the order of half a dozen to a dozen (top!). I usually think about them like this:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;
		Controllers&lt;/li&gt;
	&lt;li&gt;
		Views&lt;/li&gt;
	&lt;li&gt;
		Entities&lt;/li&gt;
	&lt;li&gt;
		Commands&lt;/li&gt;
	&lt;li&gt;
		Tasks&lt;/li&gt;
	&lt;li&gt;
		Events&lt;/li&gt;
	&lt;li&gt;
		Queries&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
	Sometimes you have a few more, but those are the major ones. Controllers,Views and Entities are fairly obvious, I would imagine. But what about the rest?&lt;/p&gt;
&lt;p&gt;
	Command is a package &amp;ldquo;thing&amp;rdquo; that happen immediately. Tasks are very like commands, except that they don&amp;rsquo;t have an explicit execution date and Events allow you to build smarts into the system. We have already seen how I handle events, in the previous posts in this series. And Queries should be fairly obvious as well.&lt;/p&gt;
&lt;p&gt;
	Let us tackle Commands now, and then explain why they are bad later on.&lt;/p&gt;
&lt;p&gt;
	When I said that I don&amp;rsquo;t want abstractions, I meant that I don&amp;rsquo;t want an interface and an implementation, and some way to connect the two, etc. I don&amp;rsquo;t really see a lot of value in that for the common case.&lt;/p&gt;
&lt;p&gt;
	Let us break it apart into commands, which would give us this:&lt;/p&gt;
&lt;blockquote&gt;
	&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AssignCargoToRoute : Command
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; Itinerary Itinerary { get;set; }
  TrackingId TrackingId { get;set; }

  &lt;span class="kwrd"&gt;public&lt;/span&gt; override &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute()
  {
    
  }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BookNewCargo : Command
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; UnLocode Origin {get;set;}
  &lt;span class="kwrd"&gt;public&lt;/span&gt; UnLocode Destination { get;set; }
  &lt;span class="kwrd"&gt;public&lt;/span&gt; DateTime ArrivalDeadline {get;set;}

  &lt;span class="kwrd"&gt;public&lt;/span&gt; TrackingId Result {get;set;}&lt;/pre&gt;
	&lt;pre class="csharpcode"&gt;
  &lt;span class="kwrd"&gt;public&lt;/span&gt; override void Execute()
  {
    
  }
}&lt;/pre&gt;
	&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }	&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	I am very fond in having a base class for those types of things. The base class provide me with the infrastructure support for the command in question.&lt;/p&gt;
&lt;p&gt;
	In my next post, I&amp;rsquo;ll go over why I don&amp;rsquo;t like this approach, and discuss other ways to structure things so it is more suitable for an actual application.&lt;/p&gt;
</description><link>http://ayende.com/blog/154081/limit-your-abstractions-you-only-get-six-to-a-dozen-in-the-entire-app?key=60fd31cb-4b9b-47f4-b357-6bc09b858581</link><guid>http://ayende.com/blog/154081/limit-your-abstractions-you-only-get-six-to-a-dozen-in-the-entire-app?key=60fd31cb-4b9b-47f4-b357-6bc09b858581</guid><pubDate>Mon, 13 Feb 2012 10:00:00 GMT</pubDate></item><item><title>The economics of continuous deployment</title><description>&lt;p&gt;
	One of the things that I did, almost by accident, when we started Hibernating Rhinos was to create a CI server and a public daily build server. And every single successful build ended up in customer hands. That was awesome in many respects, it removed a lot of the &amp;ldquo;we have got to make a new release&amp;rdquo; pressure, because we were making new releases, sometimes multiple times a day.&lt;/p&gt;
&lt;p&gt;
	When we started with RavenDB, it was obvious to me that this was what we were going to do with it as well, because the advantages to this approach as so clear. With RavenDB, we needed a two stage system, but still, every single build gets to the customer hands.&lt;/p&gt;
&lt;p&gt;
	Awesome, great, outstanding, exceptional and other such synonyms. As long as you look at this from one angle, the one in which we are only concerned about the technical challenges of delivering software .The problem is that there are additional things to note here. Economic challenges.&lt;/p&gt;
&lt;p&gt;
	Let us take the profiler as a good example. It was released in beta on the Jan 1, 2009, and since then we had 920 separate builds, adding a &lt;em&gt;ton &lt;/em&gt;of new features, capabilities, improving performance, making things smoother and in general making it a better product.&lt;/p&gt;
&lt;p&gt;
	That is over &lt;em&gt;3 years&lt;/em&gt; without a major release, mostly because we never had the need to do this, we kept delivering software on a day to day basis.&lt;/p&gt;
&lt;p&gt;
	During that time, we delivered features such as viewing the result set, checking the query plan of a query (in all major databases), exporting the entire session to HTML so you can send it to your DBA, CI integration and &lt;em&gt;so much more&lt;/em&gt;. It has been wonderful.&lt;/p&gt;
&lt;p&gt;
	Except&amp;hellip; this has one implications that I didn&amp;rsquo;t think of at the time. If you bought NH Prof on the 1st Jan, 2009 you got 3 years of product updates, for no additional costs. And unless we create a new major version, you can keep using the software, including all the updates and improvements, without paying.&lt;/p&gt;
&lt;p&gt;
	That is great for the very early customers, but not so good for the people who need to eat so they can work on the profiler. Let us think about the implications of this a bit more, okay?&lt;/p&gt;
&lt;p&gt;
	In order for us to actually make money, we have to:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		keep expanding our one-off customer base, which is going to hit a limit at some point.&lt;/li&gt;
	&lt;li&gt;
		create a new version, getting the old customer to purchase the updates.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	Seems simple, right? This is what most companies do, and how most software is sold. You get a license for version 1 and you buy a license for version 2.&lt;/p&gt;
&lt;p&gt;
	So far, so good. But let us consider the implications of that. In order to get the old users to buy the new one, I have to put some really nice stuff in the next version. Which means that I have to do a lot of &amp;ldquo;secret&amp;rdquo; development because I can&amp;rsquo;t just release it on our usual continuous deployment mode. That sucks. And it also means that features that are already coded are actually disabled because we defer them to the next version.&lt;/p&gt;
&lt;p&gt;
	So, the next version of the profilers is going to have to have some interesting features to get people to buy it. One of them is production profiling. It has actually been around for quite a while. It has simply been #ifdef&amp;rsquo;ed out of the product, because it is something that we keep for the next version.&lt;/p&gt;
&lt;p&gt;
	I just checked, and I was acutely surprised by what I found. The initial work for production profiling was done in Jan 2010, it is &lt;em&gt;working &lt;/em&gt;since then. I got side tracked with RavenDB so I never had the chance to actually complete the rest of the features for 2.x and release them all.&lt;/p&gt;
&lt;p&gt;
	In mid 2010 we started experimenting with subscriptions. Instead of having a one time payment model, we moved to a pay as you go. So as long as you were using the profiler, you were paying for it, and in return, we provided all of those new features.&lt;/p&gt;
&lt;p&gt;
	I have been thinking about this a lot lately. I strongly lean toward making the next version of the profiler (coming soon, and it will have a &lt;em&gt;bunch&lt;/em&gt; of nice features) subscription only.&lt;/p&gt;
&lt;p&gt;
	My current thinking it to allow two modes of buying the product. Monthly / yearly subscription and a one time fee that give you 18 months of usage (and doesn&amp;rsquo;t re-charge). That would allow us to keep producing software in incremental steps, without having to go away for a while and work in secret on big ticket features just so we can have enough stuff to put on &amp;ldquo;why you should buy 2.x&amp;rdquo; list.&lt;/p&gt;
&lt;p&gt;
	I would appreciate any feedback that you may have.&lt;/p&gt;
</description><link>http://ayende.com/blog/154689/the-economics-of-continuous-deployment?key=d1efe164-c458-461b-a2c7-def34546a071</link><guid>http://ayende.com/blog/154689/the-economics-of-continuous-deployment?key=d1efe164-c458-461b-a2c7-def34546a071</guid><pubDate>Fri, 10 Feb 2012 14:51:34 GMT</pubDate></item><item><title>Limit your abstractions: Application Events&amp;ndash;event processing and RX</title><description>&lt;p&gt;In my last post, I mentioned that this is actually an event processing system, so we might as well use actual event processing and see what we can gain out of this. I chose to use RX (reactive extensions), which can turn a series of events into a linq statement. This is incredibly powerful, and has some interesting implications when you combine this with your architecture. In particular, let us see what we can get when we set out to replace this with RX based event processing style.&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Application-Even_44F1/image_thumb3_thumb_thumb_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb3_thumb_thumb" border="0" alt="image_thumb3_thumb_thumb" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Application-Even_44F1/image_thumb3_thumb_thumb_thumb.png" width="907" height="180"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We can get to something like this very easily:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoProcessor : EventsProcessor
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; CargoProcessor()
    {
        On&amp;lt;Cargo&amp;gt;(cargos =&amp;gt;
            from cargo &lt;span class="kwrd"&gt;in&lt;/span&gt; cargos
            &lt;span class="kwrd"&gt;where&lt;/span&gt; cargo.Delivery.Misdirected
            select MisdirectedCargo(cargo)
            );

        On&amp;lt;Cargo&amp;gt;(cargos =&amp;gt;
            from cargo &lt;span class="kwrd"&gt;in&lt;/span&gt; cargos
            &lt;span class="kwrd"&gt;where&lt;/span&gt; cargo.Delivery.UnloadedAtDestination
            select CaroArrived(cargo)
        );
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; CaroArrived(Cargo cargo)
    {
        &lt;span class="rem"&gt;// handle event&lt;/span&gt;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; MisdirectedCargo(Cargo cargo)
    {
        &lt;span class="rem"&gt;// handle event&lt;/span&gt;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;We use RX to handle the linq processing over the events, and in EventsProcessor we have very little code, probably just:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; EventsProcessor
    {
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; List&amp;lt;Func&amp;lt;IObservable&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;, IObservable&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt;  actions = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Func&amp;lt;IObservable&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;, IObservable&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt;();

        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; On&amp;lt;T&amp;gt;(Func&amp;lt;IObservable&amp;lt;T&amp;gt;, IObservable&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;&amp;gt; action)
        {
            actions.Add(observable =&amp;gt; action(observable.OfType&amp;lt;T&amp;gt;()));
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute(IObservable&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; observable)
        {
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var action &lt;span class="kwrd"&gt;in&lt;/span&gt; actions)
            {
                action(observable).Subscribe();
            }
        }
    }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Elsewhere in the code we setup the actual Obsersable that we pass to all the EventsProcessors. The major advantages that we have with this style is that we have a natural syntax to do selection on the events that interest us, including fairly complex one. We still have easy time of creating new EventsProcessors if we want, but because the code for defining the selection is so compact, we can usually put related stuff together, which is going to be very helpful for making sure that the codebase is readable.&lt;/p&gt;
&lt;p&gt;And, naturally, this method extends itself to handling events of multiple types in the same place. For example, if we want to also handle the HandlingEvent, we can do it in place, because it is very much related to the Cargo, it seems.&lt;/p&gt;</description><link>http://ayende.com/blog/154049/limit-your-abstractions-application-eventsndash-event-processing-and-rx?key=f971dbd5-bdaa-4fd1-bd0f-518b105d0509</link><guid>http://ayende.com/blog/154049/limit-your-abstractions-application-eventsndash-event-processing-and-rx?key=f971dbd5-bdaa-4fd1-bd0f-518b105d0509</guid><pubDate>Fri, 10 Feb 2012 07:55:00 GMT</pubDate></item><item><title>When you pit RavenDB &amp;amp; SQL Server against one another&amp;hellip;</title><description>&lt;p&gt;Here is how it works. I &lt;em&gt;hate&lt;/em&gt; benchmarks, because they are very easily manipulated. Whenever I am testing performance stuff, I am posting numbers, but they are usually in reference to themselves (showing improvements).&lt;/p&gt; &lt;p&gt;That said… &lt;/p&gt; &lt;p&gt;Mark Rodseth .Net Technical Architect at &lt;a href="http://www.fortunecookie.co.uk/"&gt;Fortune Cookie&lt;/a&gt; in London, UK and he did a really interesting comparison between RavenDB &amp;amp; SQL Server. I feel good about posting this because Mark is a totally foreign agent (hm…. well, maybe not that &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://ayende.com/blog/Images/Windows-Live-Writer/RavenDB-and_11869/wlEmoticon-smile_2.png"&gt; ) but he has no association with RavenDB or Hibernating Rhinos.&lt;/p&gt; &lt;p&gt;Also, &lt;a href="http://tech-rash.blogspot.com/2012/02/is-raven-db-all-its-cracked-up-to-be.html"&gt;this post&lt;/a&gt; really made my day.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;Mark posted &lt;a href="http://tech-rash.blogspot.com/2012/02/ravendb-vs-sql-follow-up.html"&gt;more details&lt;/a&gt; on his test case.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Mark setup a load test for two identical applications, one using RavenDB, the other one using SQL Server. The results:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;b&gt;SQL Load Test&lt;/b&gt;&lt;br&gt;Transactions: 111,014 (Transaction = Single Get Request)&lt;br&gt;Failures: 110,286 (Any 500 or timeout)&lt;br&gt; &lt;p&gt;&lt;img src="http://3.bp.blogspot.com/-s8OGQmWkVGw/TzEEukU_EeI/AAAAAAAAAOE/KlBMa9Kx7jI/s400/SQLDbThroughPut.jpg"&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;And for RavenDB ?  &lt;blockquote&gt; &lt;p&gt;&lt;b&gt;RavenDB Load Test&lt;/b&gt;&lt;br&gt;Transactions: 145,554 (Transaction = Single Get Request)&lt;br&gt;Failures: 0 (Any 500 or timeout)  &lt;p&gt;&lt;img src="http://3.bp.blogspot.com/-4zPzgzwfI8U/TzEE2mxsNBI/AAAAAAAAAOM/G-f6XoqRMYE/s400/RavenDbThroughPut.jpg"&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;And now &lt;em&gt;that&lt;/em&gt; is pretty cool.&lt;/p&gt;</description><link>http://ayende.com/blog/154593/when-you-pit-ravendb-amp-sql-server-against-one-anotherhellip?key=66b0a94c-e178-4429-9d4a-238e1eec1699</link><guid>http://ayende.com/blog/154593/when-you-pit-ravendb-amp-sql-server-against-one-anotherhellip?key=66b0a94c-e178-4429-9d4a-238e1eec1699</guid><pubDate>Thu, 09 Feb 2012 16:07:00 GMT</pubDate></item><item><title>Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>&lt;p&gt;In my previous post, I spoke about ISP and how we can replace the following code with something that is easier to follow:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions_41F4/image_thumb3_thumb_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb3_thumb" border="0" alt="image_thumb3_thumb" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions_41F4/image_thumb3_thumb_thumb.png" width="907" height="180"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I proposed something like:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IHappenOn&amp;lt;T&amp;gt;
{
   &lt;span class="kwrd"&gt;void&lt;/span&gt; Inspect(T item);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Which would be invoked using:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;container.ExecuteAll&amp;lt;IHappenOn&amp;lt;Cargo&amp;gt;&amp;gt;(i=&amp;gt;i.Inspect(cargo));&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Or something like that. &lt;/p&gt;
&lt;p&gt;Which lead us to the following code:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoArrived : IHappenedOn&amp;lt;Cargo&amp;gt;
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Inspect(Cargo cargo)
  {
    &lt;span class="kwrd"&gt;if&lt;/span&gt;(cargo.Delivery.UnloadedAtDestination == &lt;span class="kwrd"&gt;false&lt;/span&gt;)
      &lt;span class="kwrd"&gt;return&lt;/span&gt;;
      
    &lt;span class="rem"&gt;// handle event&lt;/span&gt;
  }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoMisdirected : IHappenedOn&amp;lt;Cargo&amp;gt;
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Inspect(Cargo cargo)
  {
    &lt;span class="kwrd"&gt;if&lt;/span&gt;(cargo.Delivery.Misdirected == &lt;span class="kwrd"&gt;false&lt;/span&gt;)
      &lt;span class="kwrd"&gt;return&lt;/span&gt;;
      
    &lt;span class="rem"&gt;// handle event&lt;/span&gt;
  }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoHandled : IHappenOn&amp;lt;HandlingEvent&amp;gt;
{
   &lt;span class="rem"&gt;// etc&lt;/span&gt;
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; EventRegistrationAttempt : IHappenedOn&amp;lt;HandlingEventRegistrationAttempt&amp;gt;
{
  &lt;span class="rem"&gt;// etc&lt;/span&gt;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;But I don’t really like this code, to be perfectly frank. It seems to me like there isn’t really a good reason why CargoArrived and CargoMisdirected are located in different classes. It is likely that there is going to be a lot of commonalities between the different types of handling events on cargo. We might as well merge them together for now, giving us:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoHappened : IHappenedOn&amp;lt;Cargo&amp;gt;
{
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Inspect(Cargo cargo)
  {
    &lt;span class="kwrd"&gt;if&lt;/span&gt;(cargo.Delivery.UnloadedAtDestination)
      CargoArrived(cargo);
      
    
    &lt;span class="kwrd"&gt;if&lt;/span&gt;(cargo.Delivery.Misdirected)
      CargoMisdirected(cargo);
      
  }
  
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CargoArrived(Cargo cargo)
  {
    &lt;span class="rem"&gt;// handle event&lt;/span&gt;
  }
  
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CargoMisdirected(Cargo cargo)
  {
    &lt;span class="rem"&gt;//handle event&lt;/span&gt;
  }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;This code put a lot of the cargo handling in one place, making it easier to follow and understand. At the same time, the &lt;em&gt;architecture&lt;/em&gt; gives us the option to split it to different classes at any time. We aren’t going to end up with a God class for Cargo handling. But as long as it make sense, we can keep them together. &lt;/p&gt;
&lt;p&gt;I like this style of event processing, but we can probably do better job at if if we actually used event processing semantics here. I’ll discuss that in my next post.&lt;/p&gt;</description><link>http://ayende.com/blog/154017/limit-your-abstractions-application-eventsndash-proposed-solution-2ndash-cohesion?key=31944b56-4603-43ec-aff0-f84329802cce</link><guid>http://ayende.com/blog/154017/limit-your-abstractions-application-eventsndash-proposed-solution-2ndash-cohesion?key=31944b56-4603-43ec-aff0-f84329802cce</guid><pubDate>Thu, 09 Feb 2012 00:41:00 GMT</pubDate></item><item><title>Limiting your abstractions: Reflections on the Interface Segregation Principle</title><description>&lt;p&gt;I have found two definitions for ISP (in this post, I assume that you know what ISP is, if you don’t, look at the links below).&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.objectmentor.com/resources/articles/isp.pdf"&gt;This one&lt;/a&gt; I can fully agree with:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Clients should not be forced to depend upon interfaces that they don't use.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;And &lt;a href="http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf"&gt;this one&lt;/a&gt; I strongly disagree with: &lt;blockquote&gt; &lt;p&gt;Many client specific interfaces are better than one general purpose interface&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;For fun, both of those links are from Object Mentor.  &lt;p&gt;It would be more accurate to say that I don’t so much disagree with the &lt;em&gt;intent&lt;/em&gt; of the second statement, but that I disagree with the wording. One (literal) way of understanding the second statement is to say that we want specific interfaces over generic ones. And I would strongly disagree. An interface is an abstraction (for the most part), and I want to reduce the amount that I have in my system.  &lt;p&gt;Let us look at an example, based on my recent posts in this series. &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Reflections-on-the-Interface-Segregation_388F/image_thumb%5B3%5D_thumb_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb[3]_thumb" border="0" alt="image_thumb[3]_thumb" src="http://ayende.com/blog/Images/Windows-Live-Writer/Reflections-on-the-Interface-Segregation_388F/image_thumb%5B3%5D_thumb_thumb.png" width="907" height="180"&gt;&lt;/a&gt; &lt;p&gt;In my previous post, I said that I want to remove both CargoWasHandled and CargoWasMisdirected in favor of IHappenOnCargoInspection. But what about the two other methods?&lt;/p&gt; &lt;p&gt;Would ISP force me to have IHappenOnEventRegistrationAttempt and IHappenOnCargoHandling?&lt;/p&gt; &lt;p&gt;Sure, those are many specific interfaces, but are they really better than something like IHappenOn&amp;lt;T&amp;gt;? Is there something truly meaningful that gets lost when we have the generic interface?&lt;/p&gt; &lt;p&gt;I would say that this isn’t the case, further more, I would actually state that having a single interface will lead to more maintainable code, because there are less abstractions in the code. There is a codebase that is more cohesive and easier to understand.&lt;/p&gt; &lt;p&gt;But I’ll talk more about cohesion on my next post.&lt;/p&gt;</description><link>http://ayende.com/blog/153985/limiting-your-abstractions-reflections-on-the-interface-segregation-principle?key=89e01e5d-16c1-488e-a70e-477241373220</link><guid>http://ayende.com/blog/153985/limiting-your-abstractions-reflections-on-the-interface-segregation-principle?key=89e01e5d-16c1-488e-a70e-477241373220</guid><pubDate>Wed, 08 Feb 2012 07:35:00 GMT</pubDate></item><item><title>Send me a patch for that</title><description>&lt;p&gt;
	This post is in reply to &lt;a href="http://devlicio.us/blogs/hadi_hariri/archive/2012/02/06/submit-a-patch.aspx"&gt;Hadi&amp;rsquo;s post&lt;/a&gt;. Please go ahead and read it.&lt;/p&gt;
&lt;p&gt;
	Done? Great, so let me try to respond, this time, from the point of view of someone who &lt;em&gt;regularly &lt;/em&gt;asks for patches / pull requests.&lt;/p&gt;
&lt;p&gt;
	Here are &lt;a href="http://groups.google.com/group/ravendb/browse_thread/thread/e41be56d64ab17b1/8329434c8f5dca1f"&gt;a&lt;/a&gt; &lt;a href="http://groups.google.com/group/ravendb/browse_thread/thread/bb70cab7a459e57/a72da650336a6a85?lnk=gst&amp;amp;q=%22pull+request%22#a72da650336a6a85"&gt;few&lt;/a&gt; &lt;a href="http://groups.google.com/group/ravendb/browse_thread/thread/98b2ab69677c7ea/5eeb8b08064c1124?lnk=gst&amp;amp;q=pull+request#5eeb8b08064c1124"&gt;examples&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;
	To make things more interesting, the project that I am talking about now is RavenDB which is both Open Source and commercial. Hadi says:&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
		Numerous times I&amp;rsquo;ve seen reactions from OSS developers, contributors or merely a simple passer by, responding to a complaint with: &lt;strong&gt;&lt;em&gt;submit a patch &lt;/em&gt;&lt;/strong&gt;or &lt;strong&gt;&lt;em&gt;well if you can do better, write your own framework. &lt;/em&gt;&lt;/strong&gt;In other words, put up or shut up.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	Hadi then goes on to explain exactly why this is a high barrier for most users.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		You need to familiarize yourself with the codebase.&lt;/li&gt;
	&lt;li&gt;
		You need to understand the source control system that is used and how to send a patch / pull request.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	And I would fully agree with Hadi that those are stumbling blocks. I can&amp;rsquo;t speak for other people, but in our case, that is the &lt;em&gt;intention&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
		Nitpicker corner here: I am speaking explicitly and only about &lt;em&gt;features &lt;/em&gt;here. Bugs gets fixed by us (unless the user already submitted a fix as well).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	Put simply, there is an issue of priorities here. We have a certain direction for the project that we want to take it. And in many cases, users want things that are out of scope for us for the foreseeable future. Our options then become:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		Sorry, ain&amp;rsquo;t going to happen.&lt;/li&gt;
	&lt;li&gt;
		Sure, we will push aside all the work that we intended to do to do your thing.&lt;/li&gt;
	&lt;li&gt;
		No problem, we added that to the queue, expect it in 6 &amp;ndash; 9 months, if we will still consider it important then.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	None of which is an acceptable answer from our point of view.&lt;/p&gt;
&lt;p&gt;
	Case in point, facets support in RavenDB was something that was requested a few times. We never did it because it was out of scope for our plan, RavenDB is a &lt;em&gt;database&lt;/em&gt; server, not a &lt;em&gt;search&lt;/em&gt; server and we weren&amp;rsquo;t really sure how complex this would be and how to implement this. Basically, this was an expensive feature that wasn&amp;rsquo;t in the major feature set that we wanted. The answer that we gave people is &amp;ldquo;send me a pull request for that&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;
	To be clear, this is basically an opportunity to affect the direction of the project in a way you consider important. What ended up happening is that Matt Warren took up the task and created an initial implementation. Which was then subject to intense refactoring and finally got into the product. You can see the &lt;a href="http://groups.google.com/group/ravendb/browse_thread/thread/76908832b1e2a0ae/f1d0ab9a2422b96d"&gt;entire conversation about this here&lt;/a&gt;. The major difference along the way is that Matt did all the research for this feature, and he had working code. From there the balance change. It was no longer an issue of expensive research and figuring out how to do it. It was an issue of having working code and refactoring it so it matched the rest of the RavenDB codebase. &lt;em&gt;That &lt;/em&gt;wasn&amp;rsquo;t expensive, and we got a new feature in.&lt;/p&gt;
&lt;p&gt;
	Here is another story, a case where &lt;em&gt;I flat out didn&amp;rsquo;t think it was possible&lt;/em&gt;. About two years ago &lt;a href="http://codeofrob.com/"&gt;Rob Ashton&lt;/a&gt; had a feature suggestion (ad hoc queries with RavenDB). Frankly, I thought that this was simply not possible, and after a bit of back and forth, &lt;a href="http://groups.google.com/group/ravendb/browse_thread/thread/792c90f28c2141e2/f0f39e1e24aea0be"&gt;I told Rob&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
		Let me rephrase that.&lt;br /&gt;
		Dream up the API from the client side to do this.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	Rob went away for a few hours, and then came back with a &lt;em&gt;working code sample&lt;/em&gt;. I had to pick my jaw off the floor using both hands. &lt;em&gt;That &lt;/em&gt;feature got a lot of priority right away, and is a feature that I routinely brag about when talking about RavenDB.&lt;/p&gt;
&lt;p&gt;
	But let me come back again to the common case, a user request something that isn&amp;rsquo;t in the project plan. Now, remember, &lt;em&gt;requests are cheap&lt;/em&gt;. From the point of view of the user, it doesn&amp;rsquo;t cost anything to request a feature. From the point of view of the project, it can cost a lot. There is research, implementation, debugging, backward compatibility, testing and continuous support associated with just about any feature you care to name.&lt;/p&gt;
&lt;p&gt;
	And our options whenever a user make a request that is out of line for the project plan are:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		Sorry, ain&amp;rsquo;t going to happen.&lt;/li&gt;
	&lt;li&gt;
		Sure, we will push aside all the work that we intended to do to do your thing.&lt;/li&gt;
	&lt;li&gt;
		No problem, we added that to the queue, expect it in 6 &amp;ndash; 9 months, if we will still consider it important then.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	&lt;em&gt;Or&lt;/em&gt;, we can also say:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		We don&amp;rsquo;t have the resources to currently do that, but we would gladly accept a pull request to do so.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	And that point, the user is faced with a choice. He can either:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		Oh, well, it isn&amp;rsquo;t important to me.&lt;/li&gt;
	&lt;li&gt;
		Oh, it is important to me so I have better do that.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	In other words, it shift the prioritization to the user, based on how important that feature is.&lt;/p&gt;
&lt;p&gt;
	We recently got a feature request to support something like this:&lt;/p&gt;
&lt;blockquote&gt;
	&lt;pre class="csharpcode"&gt;
session.Query&amp;lt;User&amp;gt;()
   .Where(x=&amp;gt; searchInput.Name != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; x.User == searcInput.Name)
   .ToArray();&lt;/pre&gt;
	&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }	&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	I&amp;rsquo;ll spare you the details of just how complex it is to implement something like that (especially when it can also be things like: (searchInput.Age &amp;gt; 18). But the simple work around for that is:&lt;/p&gt;
&lt;blockquote&gt;
	&lt;pre class="csharpcode"&gt;
var q = session.Query&amp;lt;User&amp;gt;();
&lt;span class="kwrd"&gt;if&lt;/span&gt;(searchInput.Name != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
  q = q.Where(x=&amp;gt; x.User == searcInput.Name);

q.ToArray();&lt;/pre&gt;
	&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }	&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	Supporting the first one is &lt;em&gt;complex&lt;/em&gt;, there is a simple work around that the user can use (and I like the second option from the point of view of readability as well).&lt;/p&gt;
&lt;p&gt;
	That sort of thing get a &amp;ldquo;A pull request for this feature would be appreciated&amp;rdquo;. Because the alternative to that is to slam the door in the user&amp;rsquo;s face.&lt;/p&gt;
</description><link>http://ayende.com/blog/154305/send-me-a-patch-for-that?key=32332cde-7ea4-41c8-89be-a89a5c0ed74b</link><guid>http://ayende.com/blog/154305/send-me-a-patch-for-that?key=32332cde-7ea4-41c8-89be-a89a5c0ed74b</guid><pubDate>Tue, 07 Feb 2012 18:24:26 GMT</pubDate></item><item><title>Limit your abstractions: Application Events&amp;ndash;Proposed Solution #1</title><description>&lt;p&gt;In my previous post, I explained why I really don’t the following. &lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Application-Even_3856/image_thumb%5B3%5D_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb[3]" border="0" alt="image_thumb[3]" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Application-Even_3856/image_thumb%5B3%5D_thumb.png" width="907" height="180"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoInspectionServiceImpl : ICargoInspectionService 
{
  &lt;span class="rem"&gt;// code redacted for simplicity&lt;/span&gt;

 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InspectCargo(TrackingId trackingId)
 {
    Validate.NotNull(trackingId, &lt;span class="str"&gt;"Tracking ID is required"&lt;/span&gt;);

    Cargo cargo = cargoRepository.Find(trackingId);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
      logger.Warn(&lt;span class="str"&gt;"Can't inspect non-existing cargo "&lt;/span&gt; + trackingId);
      &lt;span class="kwrd"&gt;return&lt;/span&gt;;
    }

    HandlingHistory handlingHistory = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId);

    cargo.DeriveDeliveryProgress(handlingHistory);

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo.Delivery.Misdirected)
    {
      applicationEvents.CargoWasMisdirected(cargo);
    }

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo.Delivery.UnloadedAtDestination)
    {
      applicationEvents.CargoHasArrived(cargo);
    }

    cargoRepository.Store(cargo);
 }
}&lt;/pre&gt;
&lt;p&gt;Now, let us see one proposed solution for that. We can drop the IApplicationEvents.CargoHasArrived and IApplicationEvents.CargoWasMisdirected, instead creating the following:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IHappenOnCargoInspection
{
   &lt;span class="kwrd"&gt;void&lt;/span&gt; Inspect(Cargo cargo);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;We can have multiple implementations of this interface, such as this one:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MidirectedCargo : IHappenOnCargoInspection
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Inspect(Cargo cargo)
   {
        &lt;span class="kwrd"&gt;if&lt;/span&gt;(cargo.Delivery.Misdirected == &lt;span class="kwrd"&gt;false&lt;/span&gt;)
             &lt;span class="kwrd"&gt;return&lt;/span&gt;;

        &lt;span class="rem"&gt;// code to handle misdirected cargo.&lt;/span&gt;
   }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;In a similar fashion, we would have a CargoArrived implementation, and the ICargoInspectionService would be tasked with managing the implementation of IHappenOnCargoInspection, probably through a container. Although I would probably replace it with something like:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;container.ExecuteOnAll&amp;lt;IHappenOnCargoInspection&amp;gt;(i=&amp;gt;i.Inspect(cargo));&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;All in all, it is a simple method, but it means that now the responsibility to detect and act is centralized in each cargo inspector implementation. If the detection of misdirected cargo is changed, we know that there is just one place to make that change. If we need a new behavior, for example, for late cargo, we can do that by introducing a new class, which implement the interface. That gives us the Open Closed Principle. &lt;/p&gt;
&lt;p&gt;This is better, but I still don’t like it. There are better methods than that, but we will discuss them in another post.&lt;/p&gt;</description><link>http://ayende.com/blog/153953/limit-your-abstractions-application-eventsndash-proposed-solution-1?key=662dc140-bdc3-4774-b9dd-0e435daf3cb0</link><guid>http://ayende.com/blog/153953/limit-your-abstractions-application-eventsndash-proposed-solution-1?key=662dc140-bdc3-4774-b9dd-0e435daf3cb0</guid><pubDate>Tue, 07 Feb 2012 07:30:00 GMT</pubDate></item><item><title>Limit your abstractions: Application Events&amp;ndash;what about change?</title><description>&lt;p&gt;
	In my previous post, I showed an example of application events and asked what is wrong with them.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Application-Even_3557/image_2.png"&gt;&lt;img alt="image" border="0" height="180" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Application-Even_3557/image_thumb_3.png" style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" width="907" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoInspectionServiceImpl : ICargoInspectionService 
{
  &lt;span class="rem"&gt;// code redacted for simplicity&lt;/span&gt;

 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InspectCargo(TrackingId trackingId)
 {
    Validate.NotNull(trackingId, &lt;span class="str"&gt;&amp;quot;Tracking ID is required&amp;quot;&lt;/span&gt;);

    Cargo cargo = cargoRepository.Find(trackingId);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
      logger.Warn(&lt;span class="str"&gt;&amp;quot;Can&amp;#39;t inspect non-existing cargo &amp;quot;&lt;/span&gt; + trackingId);
      &lt;span class="kwrd"&gt;return&lt;/span&gt;;
    }

    HandlingHistory handlingHistory = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId);

    cargo.DeriveDeliveryProgress(handlingHistory);

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo.Delivery.Misdirected)
    {
      applicationEvents.CargoWasMisdirected(cargo);
    }

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo.Delivery.UnloadedAtDestination)
    {
      applicationEvents.CargoHasArrived(cargo);
    }

    cargoRepository.Store(cargo);
 }
}&lt;/pre&gt;
&lt;p&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace;
	background-color: #ffffff;
	/&lt;em&gt;white-space: pre;&lt;/em&gt;/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;
&lt;p&gt;
	This is very problematic code, from my point of view, for several reasons. Look at how it allocate responsibilities. IApplicationEvents is supposed to execute the actual event, but &lt;em&gt;deciding&lt;/em&gt; when to execute the event is left for the caller. I said several reasons, but this is the main one, all other flows from it.&lt;/p&gt;
&lt;p&gt;
	What happen when the rules for invoking an event change? What happen when we want to add a new event?&lt;/p&gt;
&lt;p&gt;
	The way this is handled is broken. It violates the Open Closed Principle, it violates the Single Responsibility Principle and it frankly annoys me.&lt;/p&gt;
&lt;p&gt;
	Can you think about ways to improve this?&lt;/p&gt;
&lt;p&gt;
	I&amp;rsquo;ll discuss some in my next post.&lt;/p&gt;
</description><link>http://ayende.com/blog/153921/limit-your-abstractions-application-eventsndash-what-about-change?key=6a086acd-ce5d-491c-a15c-a99d4737c030</link><guid>http://ayende.com/blog/153921/limit-your-abstractions-application-eventsndash-what-about-change?key=6a086acd-ce5d-491c-a15c-a99d4737c030</guid><pubDate>Mon, 06 Feb 2012 12:47:00 GMT</pubDate></item><item><title>RavenDB workshop in NDC, Oslo 4-5th June</title><description>&lt;p&gt;
	The RavenDB workshop is coming to Oslo, Norway in June!&lt;/p&gt;
&lt;p&gt;
	Join us to an intensive RavenDB hands-on workshop just before the great NDC conference starts.&lt;/p&gt;
&lt;p&gt;
	During the first day of this workshop we will get to know RavenDB and its core concepts, get comfortable with its API, learn how to build and customize indexes, and how to correctly model data for use in a document database.&lt;/p&gt;
&lt;p&gt;
	After getting familiar with all the basics in the first day, during the second day we will build on that knowledge to properly grok Map&amp;frasl;Reduce, Multi&amp;ndash;maps and other advanced usages of indexes, learn how to extend RavenDB and the various options of scaling out.&lt;/p&gt;
&lt;p&gt;
	More details on the workshop and the conference can be found &lt;a href="http://www.ndcoslo.com/Workshop/ravendb"&gt;here&lt;/a&gt;.&lt;/p&gt;
</description><link>http://ayende.com/blog/153857/ravendb-workshop-in-ndc-oslo-4-5th-june?key=e325e38e-b099-4eee-9b3f-23c4b6582112</link><guid>http://ayende.com/blog/153857/ravendb-workshop-in-ndc-oslo-4-5th-june?key=e325e38e-b099-4eee-9b3f-23c4b6582112</guid><pubDate>Sun, 05 Feb 2012 10:00:00 GMT</pubDate></item><item><title>Limit your abstractions: Application Events&amp;ndash;the wrong way</title><description>&lt;p&gt;In my previous post, I have taken a few interfaces from a &lt;a href="http://dddsample.sourceforge.net/index.html"&gt;DDD sample application&lt;/a&gt; and called the application procedural and hard to maintain. In this post, I want to show you exactly why.&lt;/p&gt; &lt;p&gt;We will start with examining this interface, and how it is used:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Application-Even_33F1/image_thumb%5B3%5D_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb[3]" border="0" alt="image_thumb[3]" src="http://ayende.com/blog/Images/Windows-Live-Writer/Limit-your-abstractions-Application-Even_33F1/image_thumb%5B3%5D_thumb.png" width="907" height="180"&gt;&lt;/a&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CargoInspectionServiceImpl : ICargoInspectionService 
{
  &lt;span class="rem"&gt;// code redacted for simplicity&lt;/span&gt;

 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InspectCargo(TrackingId trackingId)
 {
    Validate.NotNull(trackingId, &lt;span class="str"&gt;"Tracking ID is required"&lt;/span&gt;);

    Cargo cargo = cargoRepository.Find(trackingId);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
      logger.Warn(&lt;span class="str"&gt;"Can't inspect non-existing cargo "&lt;/span&gt; + trackingId);
      &lt;span class="kwrd"&gt;return&lt;/span&gt;;
    }

    HandlingHistory handlingHistory = handlingEventRepository.LookupHandlingHistoryOfCargo(trackingId);

    cargo.DeriveDeliveryProgress(handlingHistory);

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo.Delivery.Misdirected)
    {
      applicationEvents.CargoWasMisdirected(cargo);
    }

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (cargo.Delivery.UnloadedAtDestination)
    {
      applicationEvents.CargoHasArrived(cargo);
    }

    cargoRepository.Store(cargo);
 }
}&lt;/pre&gt;
&lt;p&gt;Can you see what I find painful in this code?&lt;/p&gt;</description><link>http://ayende.com/blog/153890/limit-your-abstractions-application-eventsndash-the-wrong-way?key=e710d261-037b-42c1-a431-252f4085b842</link><guid>http://ayende.com/blog/153890/limit-your-abstractions-application-eventsndash-the-wrong-way?key=e710d261-037b-42c1-a431-252f4085b842</guid><pubDate>Fri, 03 Feb 2012 07:45:00 GMT</pubDate></item></channel></rss>
