﻿<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns="http://www.w3.org/2005/Atom">
  <id>http://dotnet.uni.lodz.pl/whut/</id>
  <title>Usually.NET</title>
  <updated>2011-12-15T05:51:27+00:00</updated>
  <link href="http://dotnet.uni.lodz.pl/whut/" />
  <link rel="self" href="http://dotnet.uni.lodz.pl/whut/syndication.axd?format=atom" />
  <subtitle>Rafał Kłys's Blog</subtitle>
  <author>
    <name>Whut</name>
  </author>
  <generator uri="http://dotnetblogengine.net/" version="1.0.0.0">BlogEngine.Net Syndication Generator</generator>
  <blogChannel:blogRoll>http://dotnet.uni.lodz.pl/whut/opml.axd</blogChannel:blogRoll>
  <dc:creator>Whut</dc:creator>
  <dc:description>Rafał Kłys's Blog</dc:description>
  <dc:language>en-US</dc:language>
  <dc:title>Usually.NET</dc:title>
  <geo:lat>0.000000</geo:lat>
  <geo:long>0.000000</geo:long>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Better-ASPNET-MVC-folder-structure.aspx</id>
    <title>"Better" ASP.NET MVC folder structure</title>
    <updated>2011-07-03T12:29:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=4d1289f1-3332-432c-b0a3-492b41702563" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Better-ASPNET-MVC-folder-structure.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;Default folder structure of ASP.NET MVC looks as follows:&lt;/p&gt;
&lt;pre&gt;PROJECT#1\ 
  Areas\ 
    AREA#1\
      Controllers\    // here are all controllers from this area
      Models\         // here are models for all controllers in this this area 
      Views\          // here are subfolders named after those controllers with their views
        CONTROLLER#1\
        CONTROLLER#2\
        ...
        Shared\       // here are views shared between controllers
    AREA#2\ 
      Controllers\ 
      Models\ 
      Views\ 
        ...
    ...
Content\              // here are all css and image files
Controllers\          // here are controllers not in any area 
Models\               // here are models for all those controllers 
Scripts\              // here are all javascript files
Views\                // here are subfolders named after those controllers with their views
  ...&lt;/pre&gt;
&lt;p&gt;Such folder structure is not very manageable when project grows. To work on single controller you need to look to many folders: Models, Views, Controllers, Content, Scripts. In every one of them there are plenty of files not connected with given controller.&lt;/p&gt;
&lt;p&gt;Even bigger, but more subtle problem is with models: in this structure models can be easily shared between controllers, which look as good idea in theory, In practice every action method will need a bit different model, with one field more, one field less or with a bit different validation, so it&amp;rsquo;s easier to have separate model for every controller and every controller action and don&amp;rsquo;t try to share them. Similar situation is with sharing css or JavaScript files.&lt;/p&gt;
&lt;p&gt;To alleviate those problems in my current project we came to such folder structure:&lt;/p&gt;
&lt;pre&gt;Areas\           // it would be nicer to name it Features, but ASP.NET MVC requires that name
  AREA#1\
    Views\            // this folder is here only to satisfy ASP.NET MVC
      CONTROLLER#1\   // directly in this folder are the views for given controller (*.cshtml)
        Code\         // here is controller class, all his models, mappings, etc.
        Content\      // here are css, js used by this controller views
          Images\     // here are images
      CONTROLLER#2\
        Code\
        Content\
          Images\
      ...
      Shared\         // here is stuff shared between controllers, usually it's empty
        Code\
        Content\
          Images\
  AREA#2\
    Views\
      CONTROLLER#3\&lt;/pre&gt;
&lt;pre&gt;        ...
      ...
  ...
Views\                // this folder is here only to satisfy ASP.NET MVC
  CONTROLLER#4\&lt;/pre&gt;
&lt;pre&gt;    ...
  ...
  Shared\             // directly in this folder are: layout page, error page, etc.
    Code\             // here is shared code, for example action filters
    Content\          // here is main css file and common JavaScript files
      Images\         // here are images used by main css files&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;while you work on single controller everything is in one folder:&amp;nbsp; Areas\AREANAME\Views\CONTROLLERNAME. &lt;/li&gt;
&lt;li&gt;there is a implicit discouragement to share models/css/js between controllers &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family: &amp;quot;Tahoma&amp;quot;;"&gt;Disadvantages:&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;nested folder structure, so it is harder to navigate between controlers &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What do you thing about it?&lt;/p&gt;</summary>
    <published>2011-07-03T12:29:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Better-ASPNET-MVC-folder-structure.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=4d1289f1-3332-432c-b0a3-492b41702563</pingback:target>
    <slash:comments>35</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=4d1289f1-3332-432c-b0a3-492b41702563</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Better-ASPNET-MVC-folder-structure.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=4d1289f1-3332-432c-b0a3-492b41702563</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Lesser-known-LINQ-methods.aspx</id>
    <title>Lesser known LINQ methods</title>
    <updated>2011-07-03T11:26:37+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=0a137d2e-261a-497e-996a-3a2afb10ceb1" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Lesser-known-LINQ-methods.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;System.Linq.Enumerable is a static class with all LINQ extension methods. There are also there three methods that are not extension methods and are very usefull:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Enumerable.Empty&amp;lt;TResult&amp;gt;() – returns empty collection of elements of type TResult&lt;/li&gt;    &lt;li&gt;Enumerable.Range(int start, int count) – returns collection of integers&lt;/li&gt;    &lt;li&gt;Enumerable.Repeat&amp;lt;TResult&amp;gt;(TResult element, int count – returns collection of 'count' times repeated 'element'&lt;/li&gt; &lt;/ul&gt;</summary>
    <published>2011-07-03T11:26:37+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Lesser-known-LINQ-methods.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=0a137d2e-261a-497e-996a-3a2afb10ceb1</pingback:target>
    <slash:comments>15</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=0a137d2e-261a-497e-996a-3a2afb10ceb1</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Lesser-known-LINQ-methods.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=0a137d2e-261a-497e-996a-3a2afb10ceb1</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Viewing-big-MSMQ-messages.aspx</id>
    <title>Viewing big MSMQ messages</title>
    <updated>2011-07-02T23:23:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=f90edbec-9a49-492c-86d7-85400fa2c323" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Viewing-big-MSMQ-messages.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;MSMQ snap-in shows bodies of messages larger than about 550 characters in very unreadable form:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/image.axd?picture=msmq.png"&gt;&lt;img style="background-image: none; margin: 4px 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="msmq" src="http://dotnet.uni.lodz.pl/whut/image.axd?picture=msmq_thumb.png" border="0" alt="msmq" width="418" height="465" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In my current project we use MSMQ and this is quite annoying. There are some other MSMQ viewers, but from the free ones none supports subqueues, which we also heavily use. Eventually I wrote very simple MSMQ viewer that doesn&amp;rsquo;t have such &amp;ldquo;bug&amp;rdquo;. Here is the code: &lt;a href="https://github.com/whut/MsmqFastView"&gt;https://github.com/whut/MsmqFastView&lt;/a&gt;&lt;/p&gt;</summary>
    <published>2011-07-02T23:23:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Viewing-big-MSMQ-messages.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=f90edbec-9a49-492c-86d7-85400fa2c323</pingback:target>
    <slash:comments>14</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=f90edbec-9a49-492c-86d7-85400fa2c323</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/07/03/Viewing-big-MSMQ-messages.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=f90edbec-9a49-492c-86d7-85400fa2c323</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/06/21/Cool-git-tricks.aspx</id>
    <title>Cool git tricks</title>
    <updated>2011-06-21T19:37:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=116c042a-b675-42dd-af28-4fc9d4ccae6f" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/06/21/Cool-git-tricks.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;Below list of git commands that I need to remember and use more often:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;git stash&lt;/strong&gt; &amp;ndash; stash your changes (useful for example before rebase) without creating commit, they can later be reapplied with git stash pop &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git config --global alias.rom "rebase origin/master"&lt;/strong&gt; &amp;ndash; example of creating alias for often used git command &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git add --i FILE&lt;/strong&gt; &amp;ndash; with this you can commit parts of the file, and you can also do it graphically with git gui! &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git config --global rebase.autosquash "true"&lt;/strong&gt; &amp;ndash; after that when you have commit with message "squash! SOME_OTHER_COMMIT_BEGINNING_OF_MESSAGE" will be automatically marked as squash with git rebase --interactive &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git bisect&lt;/strong&gt; &amp;ndash; great tool to find first commit that introduces bug &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git archive HEAD &amp;gt; sources.zip&lt;/strong&gt; &amp;ndash; create zip with all sources from given commit &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git clone URL --depth 200&lt;/strong&gt; &amp;ndash; with --depth you don&amp;rsquo;t have to clone whole repository history, but only some last commits &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;.git/info/exclude&lt;/strong&gt; file &amp;ndash; when you have something to ignore, but other team members don&amp;rsquo;t, so it shoudn&amp;rsquo;t go to .gitignore &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git clean &amp;ndash;d &amp;ndash;f&lt;/strong&gt; &amp;ndash; delete all untracked files and folders &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git rerere&lt;/strong&gt; &amp;ndash; not tested yet, but probably useful when you need to resolve again and again the same conflicts after reabase &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git show-branch&lt;/strong&gt; &amp;ndash; show all your branches and some of the last commits in each &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git log master..&lt;/strong&gt; &amp;ndash; when your are on some branch shows only commits unique to this branch (and unique to master) &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git log --grep "text to find in commit messages"&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git show COMMIT&lt;/strong&gt; &amp;ndash; shows diff of given commit&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git reflog&lt;/strong&gt; &amp;ndash; shows history of all operations (commits, rebases, stashes) you have made&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git reset &amp;ndash;hard &lt;/strong&gt;&lt;strong&gt;HEAD@{1&lt;/strong&gt;&lt;strong&gt;}&lt;/strong&gt; &amp;ndash; reset HEAD to previous state from reflog&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;exec&lt;/strong&gt; in git rebase &amp;ndash;interactive &amp;ndash; to test all, all rebased commits, for example by running test suite&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;git config branch.master.mergeoptions "--ff-only"&lt;/strong&gt; &amp;ndash; disalow merge commits on master branch, this for example makes rebasing required&lt;/li&gt;
&lt;/ul&gt;</summary>
    <published>2011-06-21T19:37:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/06/21/Cool-git-tricks.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=116c042a-b675-42dd-af28-4fc9d4ccae6f</pingback:target>
    <slash:comments>14</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=116c042a-b675-42dd-af28-4fc9d4ccae6f</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/06/21/Cool-git-tricks.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=116c042a-b675-42dd-af28-4fc9d4ccae6f</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/06/05/Git-Cygwin-on-Windows.aspx</id>
    <title>Git &amp; Cygwin on Windows</title>
    <updated>2011-06-05T14:54:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=19ae7698-c006-4340-b905-d10cfb907f68" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/06/05/Git-Cygwin-on-Windows.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;&lt;a href="http://git-scm.com/"&gt;Git&lt;/a&gt; from &lt;a href="http://code.google.com/p/msysgit/"&gt;MSYSGIT&lt;/a&gt; is very slow on my Windows 7 x64. Simple operation like &amp;ldquo;git status&amp;rdquo; can take more than 5 seconds. There is even a &lt;a href="http://code.google.com/p/msysgit/issues/detail?id=320"&gt;bug&lt;/a&gt; on their site for that, but sadly it&amp;rsquo;s closed, and MSYSGIT developers appear to not care about it... So I started using Git through &lt;a href="http://www.cygwin.com/"&gt;Cygwin&lt;/a&gt;, which is much quicker here. And I have some tips to remember:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;To start cmd.exe in new window from bash (without polluting it with cygwin environment variables, like PATH) create an alias in ~/.bashrc:
&lt;p&gt;alias cmd2="cmd /C start /i \"%windir%\explorer.exe\" \"%windir%\system32\cmd.exe\""&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;To run gitk from MSYSGIT instead of Cygwin one:
&lt;p&gt;alias gitk2="cmd /C gitk"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;To have &lt;a href="http://winmerge.org/"&gt;WinMerge&lt;/a&gt;as difftool create winmerge.sh file:
&lt;p&gt;#!/bin/sh &lt;br /&gt; "/cygdrive/c/Program Files/WinMerge/WinMergeU.exe" -e -dl "Base" -dr "Mine" `cygpath -aw $1` `cygpath -aw $2`&lt;/p&gt;
&lt;p&gt;Make it executable by running&lt;/p&gt;
&lt;p&gt;chmod u+x winmerge.sh&lt;/p&gt;
&lt;p&gt;And configure it as difftool in git:&lt;/p&gt;
&lt;p&gt;git config &amp;ndash;global diff.tool "winmerge"&lt;/p&gt;
&lt;p&gt;git config &amp;ndash;global difftool.winmerge.cmd "winmerge.sh \$LOCAL \$REMOTE"&lt;/p&gt;
&lt;p&gt;And put winmerge.sh in PATH, for example by coping it to /bin, or by creating ~/bin and adding it to PATH from .bashrc like PATH=$PATH:/home/rafal/bin&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;</summary>
    <published>2011-06-05T14:54:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/06/05/Git-Cygwin-on-Windows.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=19ae7698-c006-4340-b905-d10cfb907f68</pingback:target>
    <slash:comments>53</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=19ae7698-c006-4340-b905-d10cfb907f68</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/06/05/Git-Cygwin-on-Windows.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=19ae7698-c006-4340-b905-d10cfb907f68</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/03/29/Mixins-in-NET.aspx</id>
    <title>Mixins in .NET</title>
    <updated>2011-03-29T21:00:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=9de39124-1550-49b6-8473-b95b7e7ba437" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/03/29/Mixins-in-NET.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;Today I wanted to experiment with mixins in C#, language that don&amp;rsquo;t provide such functionality. Below it&amp;rsquo;s my sample implementation of mixins using Castle Core (Castle Core is .NET IoC container, like Spring in Java).&lt;/p&gt;
&lt;p&gt;In few days I will describe what &lt;a href="http://en.wikipedia.org/wiki/Mixin"&gt;mixins&lt;/a&gt; are, why there are useful and why there are so great in languages that natively support them, like Ruby.&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;using System;
using Castle.DynamicProxy;

class Program
{
    static void Main(string[] args)
    {
        Mike mike = new Mike();

        Console.WriteLine(mike.Name); // prints Mike

        MixinGenerator mixinGenerator = new MixinGenerator();
        mike = mixinGenerator.MixIn(mike, new ICanIntroduceMyselfMixin(mike));

        Console.WriteLine(mike.Name); // prints Mike
        ICanIntroduceMyself mikeCanIntroduceHimself = (ICanIntroduceMyself)mike;
        Console.WriteLine(mikeCanIntroduceHimself.Introduce()); // prints Good morning, I'm Mike.

        Console.ReadKey();

    }
}

public interface IHaveName
{
    string Name { get; }
}

public class Mike : IHaveName
{
    public virtual string Name
    {
        get { return "Mike"; }
    }
}

public class John : IHaveName
{
    public virtual string Name
    {
        get { return "John"; }
    }
}

public interface ICanIntroduceMyself
{
    string Introduce();

    string IntroduceInEvening();
}

public class ICanIntroduceMyselfMixin : ICanIntroduceMyself
{
    private IHaveName iHaveName;

    public ICanIntroduceMyselfMixin(IHaveName iHaveName)
    {
        this.iHaveName = iHaveName;
    }

    public string Introduce()
    {
        return "Good morinig, I'm " + iHaveName.Name + ".";
    }

    public string IntroduceInEvening()
    {
        return "Good evening, I'm " + iHaveName.Name + ".";
    }
}

// Mixins infrastructure

public class MixinGenerator
{
    private ProxyGenerator proxyGenerator = new ProxyGenerator();

    public T MixIn&amp;lt;T&amp;gt;(T composingObject, object mixin)
    {
        return (T)this.proxyGenerator.CreateClassProxyWithTarget(
            typeof(T),
            new Type[] { mixin.GetType() },
            composingObject,
            new MixinInterceptor(mixin));
    }
}

public class MixinInterceptor : IInterceptor
{
    private object mixin;

    public MixinInterceptor(object mixin)
    {
        this.mixin = mixin;
    }

    public void Intercept(IInvocation invocation)
    {
        if (invocation.Method.DeclaringType.IsAssignableFrom(this.mixin.GetType()))
        {
            object result = invocation.Method.Invoke(this.mixin, invocation.Arguments);
            invocation.ReturnValue = result;
        }
        else
        {
            invocation.Proceed();
        }
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;PS Mixins are already implemented in Castle Core:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;John john = new John();
ProxyGenerator generator = new ProxyGenerator();
ProxyGenerationOptions options = new ProxyGenerationOptions();
options.AddMixinInstance(new ICanIntroduceMyselfMixin(john));
john = generator.CreateClassProxyWithTarget&amp;lt;John&amp;gt;(john, options, null);
ICanIntroduceMyself johnCanIntroduceHimself = (ICanIntroduceMyself)john;
Console.WriteLine(johnCanIntroduceHimself.IntroduceInEvening());&lt;/pre&gt;</summary>
    <published>2011-03-29T21:00:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/03/29/Mixins-in-NET.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=9de39124-1550-49b6-8473-b95b7e7ba437</pingback:target>
    <slash:comments>17</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=9de39124-1550-49b6-8473-b95b7e7ba437</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/03/29/Mixins-in-NET.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=9de39124-1550-49b6-8473-b95b7e7ba437</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/03/14/Quick-Dirty-Git-setup.aspx</id>
    <title>Quick &amp; Dirty Git setup</title>
    <updated>2011-03-14T21:23:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=202db780-8181-46e5-bddc-c3ea99e2a805" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/03/14/Quick-Dirty-Git-setup.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;ul&gt;
&lt;li&gt;Set name and email:
&lt;p&gt;git config --global user.name "FirstName LastName"     &lt;br /&gt;git config --global user.email "your@email.com"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Change editor to your favourite one (for example nano):
&lt;p&gt;git config --global core.editor "nano"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Adding aliases (shortcuts) to git commands, for example to have git ci, like svn ci:
&lt;p&gt;git config --global alias.ci &amp;ldquo;commit&amp;rdquo;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Colorful output from git, everywhere:
&lt;p&gt;git config --global color.ui "auto"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Your own graphical merge tool (replace  with your name):
&lt;p&gt;git config --global merge.tool &amp;lt;tool&amp;gt;     &lt;br /&gt;git config --global merge..cmd "command params"     &lt;br /&gt;git config --global meege..path "path to command, usefull on Windows"&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Check all config option with `git help config`&lt;/p&gt;</summary>
    <published>2011-03-14T21:23:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/03/14/Quick-Dirty-Git-setup.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=202db780-8181-46e5-bddc-c3ea99e2a805</pingback:target>
    <slash:comments>30</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=202db780-8181-46e5-bddc-c3ea99e2a805</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/03/14/Quick-Dirty-Git-setup.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=202db780-8181-46e5-bddc-c3ea99e2a805</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/03/14/Cygwin-Setup.aspx</id>
    <title>Cygwin Setup</title>
    <updated>2011-03-14T20:37:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=0ec13380-8ffd-4eda-8359-963613aa34ab" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/03/14/Cygwin-Setup.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;After installing &lt;a href="http://www.cygwin.com/"&gt;Cygwin&lt;/a&gt;, which brings great UNIX command-line tools to Windows, there are some things that you could set up, to make Cygwin even more great:).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Colorful promt (newer Cygwin installations have colorful prompt already)
&lt;p&gt;Add to end of ~/.bashrc (taken from gentoo bashrc):&lt;/p&gt;
&lt;p&gt;if [[ ${EUID} == 0 ]] ; then &lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] ' &lt;br /&gt; else&lt;br /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '&lt;br /&gt; fi&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Bash completion
&lt;p&gt;Install bash-completion from setup.exe. It will enable completion of many commands in bash, but also, at least on my machine will seriously slow down terminal start. You can disable it temporary by moving or changing extension of /etc/profile.d/bash_completion.sh.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Mintty&amp;nbsp; (newer Cygwin installations install it by default)&amp;nbsp;
&lt;p&gt;By default Cygwin's BASH is run through cmd.exe, with is quite bad terminal emulator, no resizing, no normal copy&amp;amp;paste, no UTF-8 by default, .... You can install from setup.exe mintty, with is based on Putty and provides missing from cmd.exe features.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;LANG
&lt;p&gt;You can set every program to use your mother tongue by setting LANG variable in C:\Cygwin\Cygwin.bat, for example:&lt;/p&gt;
&lt;p&gt;set LANG=pl_PL.UTF-8&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Bash history navigation with PgUp/PgDn
&lt;p&gt;After writing first few characters of previously used command, you can auto-complete rest with PgUp (and go back with PgDon) with this setting in ~/.inputrc:&lt;/p&gt;
&lt;p&gt;"\e[5~":history-search-backward&lt;br /&gt; "\e[6~":history-search-forward&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Other options
&lt;p&gt;Check ~/.bashrc to enable/disable additional BASH options like not saving duplicates in history and colored outut from more commands.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Graphical tools
&lt;p&gt;There is companion project to Cygwin, called &lt;a href="http://x.cygwin.com/"&gt;Cygwin/X&lt;/a&gt;, which provides X server and possibility to run graphical tools. But it's not only option, programs written using TCL/TK can be run without X server, so tools like gitk work!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    <published>2011-03-14T20:37:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/03/14/Cygwin-Setup.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=0ec13380-8ffd-4eda-8359-963613aa34ab</pingback:target>
    <slash:comments>25</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=0ec13380-8ffd-4eda-8359-963613aa34ab</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/03/14/Cygwin-Setup.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=0ec13380-8ffd-4eda-8359-963613aa34ab</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2011/01/03/Why-Team-Foundation-Server-is-just-bad.aspx</id>
    <title>Why Team Foundation Server is just bad</title>
    <updated>2011-01-03T18:27:10+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=71fb81d2-c082-41c1-b7d6-f564cf8eadce" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2011/01/03/Why-Team-Foundation-Server-is-just-bad.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;Recently I spend some time working with &lt;a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions/team-foundation-server"&gt;Microsoft Team Foundation Server 2010&lt;/a&gt; as a source control, and bug tracking tool. It has also integrated build server, reporting and project management capabilities, but a don’t know much about them. From my experience, TFS is a bad source control software and quite nice bug tracking tool (but you have free, probably even better alternatives, that you can’t integrate with TFS). Below are my reasons. Most of them are little frictions, things that slow you down by few seconds. Someone would say that that’s not much, but simply put, why choose tool that is worse over plenty better alternatives? As a cherry on the top you will find few really big bugs, things that show that TFS it’s definitively not even used by it authors.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;TFS uses &lt;a href="http://svnbook.red-bean.com/nightly/en/svn.basic.version-control-basics.html#svn.basic.vsn-models.lock-unlock"&gt;&lt;strong&gt;lock-modify-unlock&lt;/strong&gt;&lt;/a&gt; model to control access to files. This means that you need lock any file before you can use it. From the bright side it uses by default locks that don’t prevent other people from reading and editing files, but that defeats only advantage of lock-modify-unlock model, that is guarantee that you won't need to merge files. It’s pain when you try to do something not from inside Visual Studio, you need to lock all files &lt;strong&gt;manually&lt;/strong&gt;, apparently for no reason:). Without VS using TFS is just big PITA. &lt;/li&gt;    &lt;li&gt;TFS&lt;strong&gt; don’t see changes&lt;/strong&gt; in files that aren’t previously locked, and even &lt;strong&gt;don’t differentiates between changed and unchanged locked files&lt;/strong&gt;.That means that when you change a file in Visual Studio (which automatically locks files) and then you undo your edit, the file will appear in check-in (commit) dialog! (btw. do you remember all the *.designer.* files in VS, they will be marked as changes every time you open designer). &lt;/li&gt;    &lt;li&gt;Another bad with caused by TFS locking model: &lt;strong&gt;when you have read-only access&lt;/strong&gt; to some TFS managed solution, all the files are read only on your disk and you can’t edit then (because you can’t lock them). Of course you can manually remove read-only flag from file, but even with that &lt;strong&gt;you don’t have ability to use “diff”.&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;You can’t break lock without admin rights on TFS server… &lt;/li&gt;    &lt;li&gt;Visual Studio has tight integration with TFS, this way working with TFS locking model is not that painful, some of the operation VS performs automatically. Bad news? &lt;strong&gt;VS integration with TFS is worse&lt;/strong&gt; that integration of even free tools with other source control servers. For example moving files is marked as move, not “delete then add” in TFS (this way you see full change history), but not when you move files between projects (it works for example in &lt;a href="http://ankhsvn.open.collab.net/"&gt;AnkhSVN&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;TFS is basically an online only tool, which means for example that without connection to TFS, all your files will be automatically read only (in TFS 2010 there is a build-in workaround for that, but it cures consequence, not cause). You &lt;strong&gt;can’t even do undo while not connected to TFS&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;TFS don’t integrate with any other tools,&lt;/strong&gt; so for example if you already had some other issue tracking software (other than build-in “work items”) or document/wiki server (other than build-in ability to store unversioned word files, that is preferred way to store documentation of TFS!), you are out of luck, do all manually. For all other source control systems there are plenty of possibilities, either external tools, like &lt;a href="http://freshmeat.net/projects/scmbug/"&gt;Scmbug&lt;/a&gt;, or build-in integration, like in &lt;a href="http://markphip.blogspot.com/2007/01/integrating-subversion-with-your-issue.html"&gt;SVN&lt;/a&gt;. Likewise TFS build server only works with MSTest unit testing framework, which badness is topic for another post:). &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;There is no patch&lt;/strong&gt; functionality in TFS. In exchange you got “shelve”, that is possibility to check-in your changes to server to something like your private folder, from which other people can download them. It’s cool, but server side only, you can’t “send a patch”, and shelved changes can’t be merged somewhere else, even merging back those changes doesn’t work easily. Yes, &lt;strong&gt;applying “shelve” is not like merging patch, it’s restoring&amp;#160; saved versions of all changed&lt;/strong&gt; &lt;strong&gt;files!&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Your local copy (working copy using SVN vocabulary) of solution managed in TFS &lt;strong&gt;is not self contained&lt;/strong&gt;. Some of the data about connection between local files and TFS servers is stored somewhere else, this things are called “mappings”:). That means that you can’t just move whole folder to another location, it would break whole thing. &lt;/li&gt;    &lt;li&gt;There is also a bug in this mappings and VS: when you delete whole connection to TFS in VS all contained in it “mappings” aren’t deleted. Result: when you try to download local copy into catalog that previously hold other project in deleted “connection”, you will get error saying that this folder already holds a project, and you first should delete it. But you can’t delete it, it’s invisible in any UI after you deleted whole thing, only salvation is manual editing of some magic “mapping” files. &lt;/li&gt;    &lt;li&gt;TFS &lt;strong&gt;command line client isn’t really command line tool&lt;/strong&gt;, for example when checking in (committing) it shows graphical dialog to enter commit message! &lt;/li&gt;    &lt;li&gt;Default diff viewer doesn’t show more than added and deleted lines, functionally is almost equivalent to probably more than ten years old &lt;a href="http://en.wikipedia.org/wiki/WinDiff"&gt;WinDiff&lt;/a&gt; from Windows SDK. Yes, you can change it to other, but you must do this on file extension basis, not globally, another PITA. &lt;/li&gt;    &lt;li&gt;GUI is just bad, good example of lack of usability and user friendliness. Things that for example in free AnkhSVN take one click in TFS/VS take three (like seeing local changes). Dialog box doesn’t save last used options (like compare dialog), and are sometimes set to strange defaults (like this seeing local changes, by default it shows diff with newest server version, not your working copy one). When you click undo changes on few files, you will see dialog box with all touched files, and there is no option to view local changes in that dialog. In few places there is no “View history option”, like in check-in dialog. Double clicking on file in this dialog opens it in Notepad (!?), instead of for example in VS, or better yet, in diff program. Clicking “View history” on solution file &amp;quot;in Solution Explorer shows history only of *.sln file (!?), but clicking “Checking pending changes” will check changes of all files, not only *.sln. Check-in dialog doesn’t automatically completes filenames or changed method names (&lt;a href="http://tortoisesvn.tigris.org/"&gt;TortoiseSVN&lt;/a&gt; does). When checking-in into shelve it doesn’t even save commit message when clicking Cancel. “Shelve” option is available when you right-click on solution in Solution Explorer, but “Unshelve” is hidden only in File menu. In View History window, check-in message is in one line, so you can’t see it all without right clicking and selecting Changeset details on every separate check-in (all other graphical tools, like TortoiseSVn, Gitk, AnkhSVN shows message in multiline textbox). &lt;/li&gt;    &lt;li&gt;There is no option to browse files in past, like in Repository Explorer of TortoiseSVN, you can only manually check out single files in interesting you versions. And if you would like to still have local copy with newest version, you need first to create another “workspace”, a tool to help fixing all bad ideas about locking and online-only modes in TFS:). Also, it’s impossible to download just single file, you always must download whole solution. &lt;/li&gt;    &lt;li&gt;There is no way to revert commit in one click, what you can do is update to previous version, manually (!) copy all changed files to Desktop, then update to newest version and manually copy&amp;amp;paste contents of those files inside Visual Studio&lt;strong&gt;!!!&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;TFS tracks files when you tell him to do so (optimist can say that it’s similar to Git:)). Bad news? When you add file to project or project to solution, and then remove it, &lt;strong&gt;it will again appear in check-in dialog, even if it even don’t exists on disk&lt;/strong&gt;. And when you &lt;strong&gt;add, &lt;/strong&gt;&lt;strong&gt;change, rename or delete&lt;/strong&gt; &lt;strong&gt;(!)&lt;/strong&gt; file outside Visual Studio, TFS won’t see it also! &lt;/li&gt;    &lt;li&gt;There are plenty of other &lt;strong&gt;small bugs in VS/TFS integration&lt;/strong&gt;, on my computer when I undo change sometimes few &lt;strong&gt;empty messages boxes with error icon&lt;/strong&gt; shows up. And on all computer always when you try to undo change from check-in dialog triggered from Source Control Explorer tab &lt;strong&gt;it freezes VS&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;Even that TFS everywhere use &lt;strong&gt;locking&lt;/strong&gt;, it &lt;strong&gt;doesn’t&amp;#160; work&lt;/strong&gt; at all! You can for example lock files with option disallowing other people to edit it. This is needed for example when you want to edit some binary files. Bad news? In TFS you can lock file that is not in newest version, thus when you will try to check it in, you will get merge conflict! &lt;/li&gt; &lt;/ul&gt;  &lt;ul&gt;In short if you didn’t use TFS you &lt;a href="http://www.youtube.com/watch?feature=player_detailpage&amp;amp;v=yT1UO7v4Tig#t=41s"&gt;“do not know what horror means”&lt;/a&gt;:)&lt;/ul&gt;</summary>
    <published>2011-01-03T18:27:10+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2011/01/03/Why-Team-Foundation-Server-is-just-bad.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=71fb81d2-c082-41c1-b7d6-f564cf8eadce</pingback:target>
    <slash:comments>281</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=71fb81d2-c082-41c1-b7d6-f564cf8eadce</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2011/01/03/Why-Team-Foundation-Server-is-just-bad.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=71fb81d2-c082-41c1-b7d6-f564cf8eadce</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2010/05/16/Technical-debt.aspx</id>
    <title>Technical debt</title>
    <updated>2010-05-16T13:36:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=2ee0f26a-fc9d-4be7-96b5-f1e43ddc146d" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2010/05/16/Technical-debt.aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;p&gt;I mentioned technical debt in last post. Here is a quote from Martin Fowler post &lt;a href="http://martinfowler.com/bliki/TechnicalDebt.html"&gt;Technical Debt&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Technical Debt is a wonderful metaphor developed by Ward Cunningham to help us think about this problem. In this metaphor, doing things the quick and dirty way sets us up with a technical debt, which is similar to a financial debt. Like a financial debt, the technical debt incurs interest payments, which come in the form of the extra effort that we have to do in future development because of the quick and dirty design choice. We can choose to continue paying the interest, or we can pay down the principal by refactoring the quick and dirty design into the better design. Although it costs to pay down the principal, we gain by reduced interest payments in the future.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Martin Fowler describes further technical debt and consequences of not taking care of code quality in follow up post &lt;a href="http://martinfowler.com/bliki/TechnicalDebtQuadrant.html"&gt;Technical Debt Quadrant&lt;/a&gt;. In short terms:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The whole point of good design and clean code is to make you go faster - if it didn't people like Uncle Bob, Kent Beck, and Ward Cunningham wouldn't be spending time talking about it.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Strait to the point:) But again is hard to conform to your own rules, it’s hard to not only talk about quality and good design, but actually do it, even if it pays off. Live if complicated, software development also.&lt;/p&gt;  &lt;p&gt;Another good Marin Fowler’s artice: &lt;a href="http://martinfowler.com/articles/designDead.html"&gt;Is Design Dead?&lt;/a&gt;&lt;/p&gt;</summary>
    <published>2010-05-16T13:36:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2010/05/16/Technical-debt.aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=2ee0f26a-fc9d-4be7-96b5-f1e43ddc146d</pingback:target>
    <slash:comments>192</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=2ee0f26a-fc9d-4be7-96b5-f1e43ddc146d</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2010/05/16/Technical-debt.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=2ee0f26a-fc9d-4be7-96b5-f1e43ddc146d</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2010/05/16/Custom-ASPNET-authentication-or-how-to-conform-to-your-own-rules.aspx</id>
    <title>Custom ASP.NET authentication or how to conform to your own rules</title>
    <updated>2010-05-16T11:34:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=23607dad-a527-4f94-8538-63c22bfe11f3" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2010/05/16/Custom-ASPNET-authentication-or-how-to-conform-to-your-own-rules.aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;h3&gt;Custom ASP.NET authentication&lt;/h3&gt;  &lt;p&gt;Lately I worked on integrating ASP.NET web application with external authorization service. Luckily ASP.NET architecture is very extensible and many ASP.NET functionalities are not hard-coded into framework, but provided by instances of &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ihttpmodule.aspx"&gt;IHttpModule&lt;/a&gt;. In general those modules allows developers to hook into request processing pipeline and perform custom actions before, during and after request handling. Sole interface is very simple, provides only two methods:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public interface IHttpModule
{
    void Dispose();

    // Summary:
    //     Initializes a module and prepares it to handle requests.
    // Parameters:
    //   context:
    //     An System.Web.HttpApplication that provides access to the methods, properties,
    //     and events common to all application objects within an ASP.NET application
    void Init(HttpApplication context);
}&lt;/pre&gt;

&lt;p&gt;During application startup ASP.NET runtime will call Init method on all registered modules. Inside Init modules usually attach custom handlers for &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httpapplication.aspx"&gt;HttpApplication&lt;/a&gt; events, like AuthenticateRequest, AuthorizeRequest, BeginRequest, EndRequest, Error and many others. Standard ASP.NET services like authentication, authorization, output caching and session are provided as modules, so it’s possible (and quite easy!) to switch then to your own implementations.&lt;/p&gt;

&lt;p&gt;For example to integrate my external authorization service, I wrote something like this:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class MyAuthorizationModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.AuthenticateRequest += new EventHandler(this.HttpApplication_AuthenticateRequest);
    }

    public void Dispose()
    {
    }

    private void HttpApplication_AuthenticateRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        string username = this.AuthenticateInExternalSource(application.Context);
        if (username != null)
        {
            GenericIdentity identity = new GenericIdentity(username, &amp;quot;MyAuthentication&amp;quot;);
            application.Context.User = new GenericPrincipal(identity, new string[0]);
        }
    }

    private string AuthenticateInExternalSource(HttpContext context)
    {
        // Dummy code
        return &amp;quot;Rafał&amp;quot;;
    }
}&lt;/pre&gt;

&lt;p&gt;And provided some configuration in web.config:&lt;/p&gt;

&lt;pre class="brush: xml;"&gt;&amp;lt;configuration&amp;gt;
&amp;lt;!—- You will need to use section &amp;lt;system.webServer&amp;gt; instead when using IIS 7.0 in integrated mode --&amp;gt;
  &amp;lt;system.web&amp;gt;
    &amp;lt;!-- Disable default Windows authentication --&amp;gt;
    &amp;lt;authentication mode=&amp;quot;None&amp;quot; /&amp;gt;
    &amp;lt;httpModules&amp;gt;
      &amp;lt;add name=&amp;quot;MyAuthenticationModule&amp;quot; type=&amp;quot;MyWebApp.MyAuthorizationModule&amp;quot;/&amp;gt;
    &amp;lt;/httpModules&amp;gt;
  &amp;lt;/system.web&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/pre&gt;

&lt;p&gt;That’s all what you need to provide custom authentication service in ASP.NET! Just set User property to your own instance of IPrincipal during handling AuthenticateRequest event, register your module and disable enabled by default Windows authentication. The great part about it is that it perfectly works with other parts of ASP.NET framework, for example with roles provider.&lt;/p&gt;

&lt;h3&gt;The problem&lt;/h3&gt;

&lt;p&gt;From my external authentication service I get some more informations than just user name and I wanted to store it inside this User property and use it later. So I quickly created custom IIdentity class and committed changes:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class MyIdentity : GenericIdentity
{
    public MyIdentity(string name, string anotherId)
        : base(name, &amp;quot;MyAuthentication&amp;quot;)
    {
        this.AnotherId = anotherId;
    }

    public string AnotherId { get; private set; }
}&lt;/pre&gt;

&lt;p&gt;After a while my colleague downloaded my changes, started application and got SerializationException. I quickly found that IIdentity implementations should be serializable, quickly added [Serializable] attribute and again committed changes. This time there was another SerializationException, but with message “Type is not resolved for member…”. After looking for a while for cause, I found Rockford Lhotka &lt;a href="http://www.lhotka.net/weblog/UpdateOnMyStrugglesWithTheASPNETDevelopmentServer.aspx"&gt;post&lt;/a&gt; that help me understand what was going on. &lt;/p&gt;

&lt;p&gt;Basically setting this User property sets also principal on thread that’s serving given request. The problem lays in that in case of build-in web server in Visual Studio the same thread is used for handling request (in one &lt;a href="http://msdn.microsoft.com/en-us/library/2bh4z9hs.aspx"&gt;AppDomain&lt;/a&gt;) and for some other tasks (in another one). When you have some objects in one AppDomain and want to use them in another (and that’s the case of our custom principal attached to thread) they can’t be used directly, and must be coped (by serialization and deserialization) or proxied (by inheriting from &lt;a href="http://msdn.microsoft.com/en-us/library/system.marshalbyrefobject.aspx"&gt;MarshalByRefObject&lt;/a&gt;) instead. The other AppDomain that this build-in web server uses doesn’t have access to types declared in our assembly (.NET tries to load it, but it looks only in process working direcotry and in &lt;a href="http://en.wikipedia.org/wiki/Global_Assembly_Cache"&gt;GAC&lt;/a&gt;, and throws SerializationException. Possible solutions are: inheriting from MarshalByRefObject, installing assembly to GAC, coping it to web server working directory, trying to reset thread principal or using &lt;a href="http://msdn.microsoft.com/en-us/library/cskzh7h6.aspx"&gt;DEVPATH&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All solutions to this problem have some drawback so I decided to just drop my custom IIdentity implementation. I wanted to quickly fix this bug and not stopping my colleague soI created some static methods on my authentication module to provide the additional data that I put before in my IIdentity implementation. In my guts I felt that those static methods aren’t the best solution, but I quickly committed this change to start working on other things. &lt;/p&gt;

&lt;h3&gt;Lesson learned&lt;/h3&gt;

&lt;p&gt;Many times I heard and even say to others that code quality is very important, that in long term it always pays off to take care of design, coding standards, refactoring and testing. Software development is about managing complexity, and without paying attention to quality, great project can become real mess, a mountain of complex and intangible code. Great metaphor that nicely describes problems with quality in software projects is &lt;a href="http://martinfowler.com/bliki/TechnicalDebt.html"&gt;Technical Debt&lt;/a&gt;. Another highly recommended read!&lt;/p&gt;

&lt;p&gt;It’s easy to say “quality is important, always do things the right way, not the quick-and-dirty one”, but it’s a lot harder to do it actually. This time I managed to stop and think about better way of coding this particular feature and after a bit of work I ended with solution that I wan't be ashamed of. The point is, I need always to thing about quality, about design.&lt;strong&gt; It’s so&lt;/strong&gt; &lt;strong&gt;easy to start running&lt;/strong&gt; &lt;strong&gt;and doing things the quickest way&lt;/strong&gt;. But at the end there will always be a moment when you will have to pay back your technical debt, in long term it will always slow down development.&lt;/p&gt;</summary>
    <published>2010-05-16T11:34:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2010/05/16/Custom-ASPNET-authentication-or-how-to-conform-to-your-own-rules.aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=23607dad-a527-4f94-8538-63c22bfe11f3</pingback:target>
    <slash:comments>8</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=23607dad-a527-4f94-8538-63c22bfe11f3</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2010/05/16/Custom-ASPNET-authentication-or-how-to-conform-to-your-own-rules.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=23607dad-a527-4f94-8538-63c22bfe11f3</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2010/04/07/When-its-good-enough-also-about-ASPNET-validators-and-Captcha.aspx</id>
    <title>When it’s good enough – also about ASP.NET validators and Captcha</title>
    <updated>2010-04-07T11:12:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=a73819a8-f2e5-4e30-b347-c64758e37198" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2010/04/07/When-its-good-enough-also-about-ASPNET-validators-and-Captcha.aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;p&gt;Lately I encounter a lot of comment spam on my blog. There are many possibilities to fight such spam: filters like Akismet, different kinds of &lt;a href="http://en.wikipedia.org/wiki/Captcha"&gt;Captcha&lt;/a&gt; or just required registration. Of course I decided to create my own simple Captcha control for ASP.NET. There are many others available, but I wanted to make my own for educational purposes &amp;ndash; do you hear &lt;a href="http://en.wikipedia.org/wiki/Not_Invented_Here"&gt;NIH&lt;/a&gt; ;)?&lt;/p&gt;
&lt;p&gt;Finally I created two controls inheriting from &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalidator.aspx"&gt;BaseValidator&lt;/a&gt;, one that ask question like:&lt;/p&gt;
&lt;pre class="brush: plain;"&gt;Answer using words not digits: twelve minus three equals&lt;/pre&gt;
&lt;p&gt;And second that just renders empty and hidden &amp;lt;input&amp;gt; and checks if spam bot accidentally filled it. The first one works very well on my blog, I have no spam right now. Probably it wouldn&amp;rsquo;t be so effective on highly visited and popular sites - spammers would just create a spambot that would handle it, but my site is not so popular to bother.&lt;/p&gt;
&lt;h3&gt;Problem&lt;/h3&gt;
&lt;p&gt;All validators in ASP.NET follows the same schema: they are used to check validity of some other control and eventually render error message. My Captcha behaves differently: it always render something (question or empty input) and doesn&amp;rsquo;t validate any other control. I had to change some behaviors of BaseValidator in my inherited controls and ignore some properties from this base class. You can see it in attached source code in AbstractCaptchaValidator class.&lt;/p&gt;
&lt;h3&gt;SOLID&lt;/h3&gt;
&lt;p&gt;Robert C. Martin created SOLID, acronym for five basic principles of object-oriented design. There are great guidelines how to think about responsibilities and interactions of classes. You should really check them out on his old &lt;a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod"&gt;site&lt;/a&gt;, or in his book, &lt;a href="http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445"&gt;Agile Principles, Patterns and Practices&lt;/a&gt;, also available in &lt;a href="http://www.amazon.com/Principles-Patterns-Practices-Robert-Martin/dp/0131857258"&gt;C# version&lt;/a&gt;. Highly recommended.&lt;/p&gt;
&lt;p&gt;One of those rules is Liskov Substitution Principle:&lt;/p&gt;
&lt;pre class="brush: plain;"&gt;Derived classes must be substitutable for their base classes.&lt;/pre&gt;
&lt;p&gt;My Captcha controls of course violates this principle.&lt;/p&gt;
&lt;h3&gt;Solution&lt;/h3&gt;
&lt;p&gt;In attached source code you can find my second attempt to create Captcha, this time as composite control, that internally renders Label with question, TextBox for answer and &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.comparevalidator.aspx"&gt;CompareValidator&lt;/a&gt; to check if given answer is correct. Another possibility is to implement the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.ivalidator.aspx"&gt;IValidator&lt;/a&gt; interface which doesn&amp;rsquo;t assume all behaviors of BaseValidator, but I lost source code for this.&lt;/p&gt;
&lt;h3&gt;Lesson learned&lt;/h3&gt;
&lt;p&gt;It&amp;rsquo;s good to look for better solutions and fight against code with complicated, not obvious and surprising behavior. SOLID principles are good guide for that. It makes your work easier in long run.&lt;/p&gt;
&lt;p&gt;But the real point of this post is something different. It&amp;rsquo;s sometimes hard to recognize when given solution to some problem is good enough. In reality (in job particularly) it doesn&amp;rsquo;t need to be always the best and perfect one, sometimes good enough is &lt;strong&gt;good enough&lt;/strong&gt;. Usually there is a need to weight pros and cons of better and worse solution, consider time frame, familiarity with given domain, abilities of team, &amp;hellip; How to make a good decision? I think that I just need to be beware of those tradeoffs and be conscious.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/file.axd?file=MyCaptchaLib.zip" target="_self"&gt;MyCaptchaLib.zip&lt;/a&gt;&lt;/p&gt;</summary>
    <published>2010-04-07T11:12:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2010/04/07/When-its-good-enough-also-about-ASPNET-validators-and-Captcha.aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=a73819a8-f2e5-4e30-b347-c64758e37198</pingback:target>
    <slash:comments>53</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=a73819a8-f2e5-4e30-b347-c64758e37198</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2010/04/07/When-its-good-enough-also-about-ASPNET-validators-and-Captcha.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=a73819a8-f2e5-4e30-b347-c64758e37198</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2010/03/01/Retention-of-NET-attributes-like-in-Java.aspx</id>
    <title>Retention of .NET attributes like in Java</title>
    <updated>2010-03-01T19:02:37+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=70e40005-6e37-4f0f-9439-a71dca8d2412" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2010/03/01/Retention-of-NET-attributes-like-in-Java.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;p&gt;In Java you can decide if &lt;a href="http://dotnet.uni.lodz.pl/whut/post/2009/08/08/C-attributes-are-nice-C-attributes.aspx"&gt;attributes&lt;/a&gt;, called there annotations, should be persisted only in source code, also in compiled .class files or even at runtime. You use special annotation, @Retention, to specify that. Java compiler starting from Java 5 supports annotations and this special meta-annotation (meta, because it’s annotation on annotation:) ). It’s something like that possible in .NET?&lt;/p&gt;  &lt;p&gt;Of course;) In .NET you can use special &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx"&gt;Conditional&lt;/a&gt; attribute. This attribute allows us to decide if given method call or attribute should be ignored unless a specified compilation symbol is defined. Example:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public class Program
{
    static void Main(string[] args)
    {
        Assert.AreEqual(1, 2);
    }
}

public class Assert
{
    [Conditional(&amp;quot;DEBUG&amp;quot;)]
    public static void AreEqual(int number1, int number2)
    {
        if (number1 != number2)
        {
            throw new Exception(&amp;quot;Arguments aren't equal.&amp;quot;);
        }
    }
}&lt;/pre&gt;

&lt;p&gt;“DEBUG” is standard compilation symbol which is specified by default when you compile Debug version of standard Visual Studio project. Above code will throw exception when compiled in Debug mode. But when you compile it in Release configuration, nothing will happen, Assert.AreEqual method will not be even called. You can do the same with attributes:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;[Conditional(&amp;quot;USE_BEST&amp;quot;)]
public sealed class BestAttribute : Attribute
{
}&lt;/pre&gt;

&lt;p&gt;This attribute when used on class,method and so on, will not be actually applied if “USE_BEST” symbol will not be declared.&lt;/p&gt;

&lt;p&gt;When Conditional attribute is useful?&lt;/p&gt;

&lt;p&gt;When used on other attributes it’s possible to create attribute that will serve only documentation purposes. But you can use regular comments for that:). Another reasons for use of Conditional are situations when you have many deployments, and in some places you for example need to call some function and in others not. You can also use it to implement your own trace or assert framework, but that is already created by Microsoft (see &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.aspx"&gt;Debug&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.aspx"&gt;Trace&lt;/a&gt; classes).&lt;/p&gt;</summary>
    <published>2010-03-01T19:02:37+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2010/03/01/Retention-of-NET-attributes-like-in-Java.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=70e40005-6e37-4f0f-9439-a71dca8d2412</pingback:target>
    <slash:comments>63</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=70e40005-6e37-4f0f-9439-a71dca8d2412</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2010/03/01/Retention-of-NET-attributes-like-in-Java.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=70e40005-6e37-4f0f-9439-a71dca8d2412</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2010/02/19/JSON-parser-using-ExpandoObject.aspx</id>
    <title>JSON parser using ExpandoObject</title>
    <updated>2010-02-19T17:28:01+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=a02ec7f1-0dfa-46ba-914c-7c173e480e55" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2010/02/19/JSON-parser-using-ExpandoObject.aspx" />
    <author>
      <name>whut</name>
    </author>
    <summary type="html">&lt;h3&gt;JSON&lt;/h3&gt;  &lt;p&gt;Lately I wanted to know what JSON is. And it appeared that is very nice data-interchange format. It’s a lot simpler than XML and probably could be used in all scenarios when XML is used. Just look at &lt;a href="http://json.org"&gt;json.org&lt;/a&gt; and you will learn JSON in about 2 minutes. That’s nice:) It’s so simple that I fought that I will create for fun simple JSON parser using ExpandoObject. And, as usual, I learn something important:)&lt;/p&gt;  &lt;h3&gt;ExpandoObject&lt;/h3&gt;  &lt;p&gt;.NET 4.0 integrates &lt;a href="http://msdn.microsoft.com/en-us/library/dd233052(VS.100).aspx"&gt;DLR&lt;/a&gt;, which is Dynamic Language Runtime. What’s it? DLR allows to use construct’s previously possible only in dynamically typed languages. For example in C# you can declare variable as “dynamic”, and use it like variables in PHP, JavaScript, Python or Ruby&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;dynamic x = new List&amp;lt;int&amp;gt;();
Console.WriteLine(x.Count);
x = new int[0];
Console.WriteLine(x.Length);
x = &amp;quot;It's dynamic!&amp;quot;;
Console.WriteLine(x);
// This line throws exception because there is no MyMethod on string object.
// x.MyMethod();&lt;/pre&gt;

&lt;p&gt;To find out more about “dynamic”, be sure to check Chris Burrow’s &lt;a href="http://blogs.msdn.com/cburrows/archive/tags/dynamic/default.aspx"&gt;blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In .NET 4.0 introduce also &lt;a href="http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject(VS.100).aspx"&gt;ExpandoObject&lt;/a&gt;, very smart example of using new “dynamic” possibilities. It allows to declare object members on the fly (it sound to me like JavaScript!).&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;dynamic expando = new ExpandoObject();
expando.Member1 = &amp;quot;Foo&amp;quot;;
expando.Member2 = &amp;quot;Bar&amp;quot;;
expando.ToString = (Action)delegate { return expando.Member1 + &amp;quot; &amp;quot; + expando.Member2; };
Console.WriteLine(expando.Member1);
Console.WriteLine(expando.Member2);
Console.WriteLine(expando.ToString());&lt;/pre&gt;

&lt;p&gt;To find out how it works check &lt;a href="http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject(VS.100).aspx"&gt;DynamicObject&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.dynamic.idynamicmetaobjectprovider(VS.100).aspx"&gt;IDynamicMetaObjectProvider&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;JSON Parser using ExpandoObject&lt;/h3&gt;

&lt;p&gt;ExpandoObject is perfect for creating simple JSON parser. This shows how it works:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;[TestMethod]
public void ObjectStringMembers()
{
    dynamic result = new JsonParser().Parse(&amp;quot;{\&amp;quot;Foo\&amp;quot;: \&amp;quot;foo\&amp;quot;, \&amp;quot;Bar\&amp;quot;: 123}&amp;quot;);
    Assert.AreEqual(&amp;quot;foo&amp;quot;, result.Foo);
    Assert.AreEqual(123.0, result.Bar);
}&lt;/pre&gt;

&lt;p&gt;I’m quite sure that my parser implements full JSON specification found in RFC &lt;a href="http://www.ietf.org/rfc/rfc4627.txt"&gt;4627&lt;/a&gt; and in only 176 lines of executable code (425 with comments, superfluous braces and so).&lt;/p&gt;

&lt;h3&gt;Lesson learned&lt;/h3&gt;

&lt;p&gt;First when I started to implement JSON parser, I thought about using regular expression. Luckily I remember quote from Jamie Zawinski:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Some people, when confronted with a problem, think &amp;quot;I know, I'll use regular expressions.&amp;quot; Now they have two problems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I quickly drop this idea. Then I tried to use inputJSONString.Split(‘,’) and use the output of that to parse JSON. This time it took me about 30 minutes to find out that it’s another wrong approach. At last I get &lt;a href="http://www.joelonsoftware.com/articles/fog0000000319.html"&gt;back to basics&lt;/a&gt; and used old knowledge gained on compilers theory lectures. And now I have simple parser which use something like LL(1) grammar:). What I learned is that I really need to know the basic, things like compilers theory, assembler, WinAPI, bytes and CPU instructions, JIT, XML, SOAP, a lot of things. If you thing it’s not needed, read article linked in next-to-last statement, it’s a good one. You can download the parser below.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:8385d1e5-32b6-4d39-a873-be1bd5524844" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/file.axd?file=JsonParser.cs" target="_self"&gt;JsonParser.cs&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:a59c013d-96f1-452d-b678-d93b56d4edda" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/file.axd?file=JsonParserTests.cs" target="_self"&gt;JsonParserTests.cs&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;</summary>
    <published>2010-02-19T17:28:01+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2010/02/19/JSON-parser-using-ExpandoObject.aspx#comment" />
    <dc:publisher>whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=a02ec7f1-0dfa-46ba-914c-7c173e480e55</pingback:target>
    <slash:comments>11</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=a02ec7f1-0dfa-46ba-914c-7c173e480e55</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2010/02/19/JSON-parser-using-ExpandoObject.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=a02ec7f1-0dfa-46ba-914c-7c173e480e55</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2010/02/13/Visual-Studio-2010-Start-Page-Customization-Remove-Connect-To-Team-Foundation-Server-from-default-Start-Page.aspx</id>
    <title>Visual Studio 2010 Start Page Customization - Remove “Connect To Team Foundation Server” from default Start Page</title>
    <updated>2010-02-13T04:15:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=5f3ec14e-d441-4cb1-8d28-1bb6eb407ec3" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2010/02/13/Visual-Studio-2010-Start-Page-Customization-Remove-Connect-To-Team-Foundation-Server-from-default-Start-Page.aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;strong&gt;:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;You can now easily create custom Start Page based on default one using &amp;nbsp;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/f655a5dc-1a2d-4eca-b774-76c352c03b87"&gt;Custom Start Page Project Template&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In Visual Studio 2010 you can easily change Start Page. Just put your version of Start Page inside MyAccount/Documents/Visual Studio 10/StartPages and select it in Tools &amp;ndash;&amp;gt; Options&amp;hellip; &amp;ndash;&amp;gt; Environment &amp;ndash;&amp;gt; Startup. You can find more info on &lt;a href="http://msdn.microsoft.com/en-us/library/ee663382(VS.100).aspx"&gt;MSDN&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/image.axd?picture=optionsStartup.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Default Start Page" src="http://dotnet.uni.lodz.pl/whut/image.axd?picture=optionsStartup_thumb.png" alt="Default Start Page" width="504" height="292" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Remove &amp;ldquo;Connect To Team Foundation Server&amp;rdquo;!&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/image.axd?picture=removetfs.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Remove TFS" src="http://dotnet.uni.lodz.pl/whut/image.axd?picture=removetfs_thumb.png" border="0" alt="Remove TFS" width="244" height="192" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Save copy of default Start Page in MyAccount/Documents/Visual Studio 10/StartPages/MyStartPage.xaml (if you don&amp;rsquo;t have it, check instructions below) &lt;/li&gt;
&lt;li&gt;Find Grid named commandButtonsGrid (line 26.) &lt;/li&gt;
&lt;li&gt;Remove first ImageButton with x:UID="ConnectoToTSButton" &lt;/li&gt;
&lt;li&gt;Remove first two RowDefinition elements from Grid.RowDefinitions &lt;/li&gt;
&lt;li&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/image.axd?picture=gridTFS.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="startpage.xaml" src="http://dotnet.uni.lodz.pl/whut/image.axd?picture=gridTFS_thumb.png" border="0" alt="startpage.xaml" width="468" height="312" /&gt;&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Change Row in second ImageButton to Row=&amp;rdquo;0&amp;rdquo; and in third to Row="2" &lt;/li&gt;
&lt;li&gt;Save file and select it as new Start Page from Options like described above. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/image.axd?picture=notfs.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Start Page without TFS" src="http://dotnet.uni.lodz.pl/whut/image.axd?picture=notfs_thumb.png" border="0" alt="Start Page without TFS" width="339" height="219" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;How to extract default Start Page from Visual Studio 2010&lt;/h3&gt;
&lt;p&gt;In Beta 2 of Visual Studio 2010 it was easy to start from default Start Page just by simply coping it from MyAccount/Documents/Visual Studio 10/StartPages/StartPage.xaml to new file. In RC this file disappeared from that location, but it&amp;rsquo;s still on your hard drive, but this time in&lt;/p&gt;
&lt;p&gt;C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\en\Microsoft.VisualStudio.Shell.UI.Internal.resources.dll&lt;/p&gt;
&lt;p&gt;Exactly inside this assembly in startpage.baml in resource file named Microsoft.VisualStudio.Shell.UI.Internal.g.en.resources. Below view of this file from &lt;a href="http://www.red-gate.com/products/reflector/"&gt;Reflector&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://dotnet.uni.lodz.pl/whut/image.axd?picture=resourceStartPage.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Reflector" src="http://dotnet.uni.lodz.pl/whut/image.axd?picture=resourceStartPage_thumb.png" border="0" alt="Reflector" width="504" height="279" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you wan to extract XAML source of this file download &lt;a href="http://reflectoraddins.codeplex.com/wikipage?title=BamlViewer&amp;amp;referringTitle=Home"&gt;BamlViewer&lt;/a&gt; add-in to Reflector. Sadly BamlViewer is not good enough to extract fully working XAML source, it appears that it have problems with XML namespaces and attached properties. You will have to fix some problems manually, save startpage.xaml to disk using BamlViewer and:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Replace Static with x:Static &lt;/li&gt;
&lt;li&gt;Replace StartPageBackgroundKey with vsfx:VsBrushes.StartPageBackgroundKey &lt;/li&gt;
&lt;li&gt;Replace StartPageSeparatorKey with vsfx:VsBrushes.StartPageSeparatorKey &lt;/li&gt;
&lt;li&gt;Replace Column, Row, ColumnSpan with Grid.Column, Grid.Row, Grid.ColumnSpan &lt;/li&gt;
&lt;li&gt;Replace AutomationId with AutomationProperties.AutomationId &lt;/li&gt;
&lt;li&gt;Replace Name="Recent Projects" with Name="RecentProjects" &lt;/li&gt;
&lt;li&gt;Replace TabNavigation with KeyboardNavigation.TabNavigation &lt;/li&gt;
&lt;li&gt;Replace HorizontalScrollBarVisibility with ScrollViewer.HorizontalScrollBarVisibility &lt;/li&gt;
&lt;li&gt;Replace SetUrl with sp:RssCommands.SetUrl &lt;/li&gt;
&lt;li&gt;Move &amp;lt;DataTemplate.Triggers&amp;gt; at the bottom of parent &amp;lt;DataTemplate&amp;gt; &lt;/li&gt;
&lt;li&gt;Replace Browse with sp:VSCommands.Browse &lt;/li&gt;
&lt;li&gt;Remove Name="{Binding XPath=title}" &lt;/li&gt;
&lt;li&gt;Replace EnableDownload with sp:RssCommands.EnableDownload &lt;/li&gt;
&lt;li&gt;Replace {x:Static PromptForCredentials} with {x:Static sp:RssCommands.PromptForCredentials} &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;rsquo;m sure this file will be easier to obtain in future:)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;PS TFS is not and probably never be as popular as MS would like it to be:)&lt;/p&gt;
&lt;p&gt;PS After clean installation (including deletion of all settings) of Visual Studio 2010, in my Documents folder VS created three catalogs: Visual Studio 10, Visual Studio 2008, Visual Studio 2010. Worse than in VS2008, then I had only two: Visual Studio 2008 and Visual Studio 2005.&lt;/p&gt;
&lt;p&gt;PS 2 Today when I wanted to shutdown my computer, which I don&amp;rsquo;t do very often because I just close the lid and suspend, I saw the usual options in Windows Vista/Seven: Switch user, Log off, Lock, Restart, Hibernate, Shutdown. My first fought was: what the hell &lt;a href="http://nhforge.org"&gt;nHibernate&lt;/a&gt; is doing here:)&lt;/p&gt;</summary>
    <published>2010-02-13T04:15:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2010/02/13/Visual-Studio-2010-Start-Page-Customization-Remove-Connect-To-Team-Foundation-Server-from-default-Start-Page.aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=5f3ec14e-d441-4cb1-8d28-1bb6eb407ec3</pingback:target>
    <slash:comments>158</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=5f3ec14e-d441-4cb1-8d28-1bb6eb407ec3</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2010/02/13/Visual-Studio-2010-Start-Page-Customization-Remove-Connect-To-Team-Foundation-Server-from-default-Start-Page.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=5f3ec14e-d441-4cb1-8d28-1bb6eb407ec3</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2010/02/03/How-to-learn.aspx</id>
    <title>How to learn?</title>
    <updated>2010-02-03T21:45:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=7c9dd6fa-0a93-4fd6-91da-9d7b008b1b0f" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2010/02/03/How-to-learn.aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;p&gt;Lately I was wandering what's the best way to be better developer (or to be more concrete in my circumstances: how to become good developer). Here are some notes for me to remember:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read books, there are a lot better source of knowledge than tech-blogs. I think that tech-blogs are great when you want to find a solution for a specific problem or master something, but when you are learning, you need to have deep knowledge of fundamentals and you won't find it elsewhere, only in books&lt;/li&gt;
&lt;li&gt;When you learning new concept try to ask yourself question: Why is it done this way?&lt;/li&gt;
&lt;li&gt;When I read book, I should more often use computer to try things in practice. I see now that I understand more, deeper and it last for longer then. So next time when I will don't fully understand something or I will have some doubts or I will&amp;nbsp; just learn something new, I will just fire Visual Studio and play with it:)&lt;/li&gt;
&lt;li&gt;Write software. There are two not exclusive possibilities: work as developer (I'm not right now) or contribute to some open-source project. Why? Because you need to share and confront your ideas with others. First of all, you need to have those ideas and you won't have them if you just reading/learning but not inventing/solving real problems.&lt;/li&gt;
&lt;li&gt;Read blogs, but not to much at the same time:)&lt;/li&gt;
&lt;li&gt;Don't be too focused on API, try to thing in more abstract terms, both in thinking about how this technology is created and how you will use it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We will see how those advices will be useful for me:)&lt;/p&gt;
&lt;p&gt;PS Look at Udi Dahan's presentation: &lt;a title="Make roles explicit" href="http://www.infoq.com/presentations/Making-Roles-Explicit-Udi-Dahan" target="_blank"&gt;Making roles explicit&lt;/a&gt;. Not on this topic, but great and mind blowing.&lt;/p&gt;</summary>
    <published>2010-02-03T21:45:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2010/02/03/How-to-learn.aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=7c9dd6fa-0a93-4fd6-91da-9d7b008b1b0f</pingback:target>
    <slash:comments>16</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=7c9dd6fa-0a93-4fd6-91da-9d7b008b1b0f</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2010/02/03/How-to-learn.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=7c9dd6fa-0a93-4fd6-91da-9d7b008b1b0f</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2009/11/16/Go-to-Implementation-and-Visual-Studio-2010.aspx</id>
    <title>Go to Implementation and Visual Studio 2010</title>
    <updated>2009-11-16T21:19:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=a1eba59a-5369-4af6-86d2-bbb3b8014900" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2009/11/16/Go-to-Implementation-and-Visual-Studio-2010.aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;p&gt;There is a nice feature in Visual Studio called &amp;ldquo;Go to Definition&amp;rdquo;. As name implies, when you point to, for example, to method invocation and use this option from context menu (or use F12 hotkey), VS will navigate to definition of this method. It really speed up writing code, when you can quickly jump between methods without remembering in which file it&amp;rsquo;s defined. It&amp;rsquo;s even more useful when you read someone else&amp;rsquo;s code. It works also with fields, properties, events, variables and so on.&lt;/p&gt;
&lt;h3&gt;Problem&lt;/h3&gt;
&lt;p&gt;Sadly it doesn&amp;rsquo;t work especially good with interfaces:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;IMyComponent component = getMyComponent();
component.MyMethod();&lt;/pre&gt;
&lt;p&gt;Now when I go to definition of MyMethod, VS will show me this:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public interface IMyComponent
{
    void MyMethod();

    ...
}&lt;/pre&gt;
&lt;p&gt;What I would actually want is to navigate to implementation of this method. Of course there could be many implementations of this method and that would require some sort of dialog to choose which implementation to show.&lt;/p&gt;
&lt;h3&gt;Solutions?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Resharper plugin to Visual Studio which have such functionality (&lt;a href="http://www.jetbrains.com/resharper/features/navigation_search.html#Go_to_Inheritor"&gt;Go to Inheritor&lt;/a&gt; and &lt;a href="http://www.jetbrains.com/resharper/features/navigation_search.html#Go_to_Implementation"&gt;Go to Implementation&lt;/a&gt;). &lt;/li&gt;
&lt;li&gt;Upgrade to Visual Studio 2010. In Beta 2 there is an option called Call Hierarchy, which allows you to see implementations of methods, but it won&amp;rsquo;t work when pointing to whole interface instead of particular method and it shows not only implementations but also calls to and from given method. See it &lt;a href="http://blogs.msdn.com/vseditor/archive/2009/09/22/searching-and-navigating-code-in-visual-studio-2010.aspx"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;</summary>
    <published>2009-11-16T21:19:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2009/11/16/Go-to-Implementation-and-Visual-Studio-2010.aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=a1eba59a-5369-4af6-86d2-bbb3b8014900</pingback:target>
    <slash:comments>9</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=a1eba59a-5369-4af6-86d2-bbb3b8014900</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2009/11/16/Go-to-Implementation-and-Visual-Studio-2010.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=a1eba59a-5369-4af6-86d2-bbb3b8014900</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2009/11/16/Introduction-to-Inverson-of-Control-magic.aspx</id>
    <title>Introduction to Inverson of Control magic</title>
    <updated>2009-11-16T20:13:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=a6ef3f13-ab08-44fb-97d9-4798c4566a6a" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2009/11/16/Introduction-to-Inverson-of-Control-magic.aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;p&gt;There is a great &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_control"&gt;Inversion of Control&lt;/a&gt; container called &lt;a href="http://www.castleproject.org/container"&gt;Windsor&lt;/a&gt;. With &lt;span&gt;IoC&lt;/span&gt; container you can easily break dependencies, make your code more testable, and do more funky stuff that I will show you later. And in very easy way! I&amp;rsquo;m still not a guy who&amp;rsquo;s able to describe something in nice words, so I will show you what is IoC container on examples:&lt;/p&gt;
&lt;h3&gt;Resolving implementations&lt;/h3&gt;
&lt;pre class="brush: csharp;"&gt;public interface ILogger
{
    void Log(string message);
}

public class ConsoleLogger : ILogger
{
    public void Log(string message)
    {
        Console.WriteLine(message);
    }
}

public static void Main()
{
    // Configuration
    WindsorContainer container = new WindsorContainer();
    container.Register(Component.For&amp;lt;ILogger&amp;gt;().ImplementedBy&amp;lt;ConsoleLogger&amp;gt;());

    // Usage
    ILogger logger = container.Resolve&amp;lt;ILogger&amp;gt;();
    logger.Log("Information.");

    // Output
    // "Information."
}&lt;/pre&gt;
&lt;p&gt;First function of container is giving you implementation for given interface. Which implementation it will return can be configured in different ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;"classic" XML configuration file &lt;/li&gt;
&lt;li&gt;"modern" &lt;a href="http://martinfowler.com/bliki/FluentInterface.html"&gt;fluent interface API&lt;/a&gt;, which you see in above example &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a side note I think that you should start using Windsor with XML configuration, to better see all the options, and then quickly switch to less verbose and error prone fluent API. If you think that this way you will loose possibility to change configuration without recompilation see &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.csharp.csharpcodeprovider.aspx"&gt;dynamic compilation&lt;/a&gt;, &lt;a href="http://ironpython.codeplex.com/"&gt;IronPython&lt;/a&gt; and &lt;a href="http://ayende.com/wiki/Rhino+Commons+-+Binsor.ashx"&gt;Binsor&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The best part about this &amp;ldquo;giving you implementation for given interface&amp;rdquo; is that Windsor can actually resolve all the dependencies. It means that it can automatically provide constructor arguments and set all public properties. Like here:&lt;/p&gt;
&lt;h3&gt;Resolving dependencies&lt;/h3&gt;
&lt;pre class="brush: csharp;"&gt;public interface IProductionClass
{
    int DoWork();
}

public class ProductionClass : IProductionClass
{
    public ILogger Logger { get; set; }

    public string Name { get; set; }

    public int DoWork()
    {
        Logger.Log(this.Name + ": DoWork");
        Thread.Sleep(100);
        return 1;
    }
}

class Program
{
    public static void Main()
    {
        // Configuration
        WindsorContainer container = new WindsorContainer();
        container.Register(Component.For&amp;lt;ILogger&amp;gt;().ImplementedBy&amp;lt;ConsoleLogger&amp;gt;());
        container.Register(Component.For&amp;lt;IProductionClass&amp;gt;().ImplementedBy&amp;lt;ProductionClass&amp;gt;());

        // Usage
        IProductionClass productionClass = container.Resolve&amp;lt;IProductionClass&amp;gt;(
            new { Name = "MyProductionClass" }
        );

        productionClass.DoWork();

        // Output
        // "MyProductionClass: Do Work"
    }
}&lt;/pre&gt;
&lt;p&gt;Example above shows a ProductionClass, which uses ILogger. Windsor automatically sets Logger property of ProductionClass to registered implementation. It also sets Name property to value shown in argument to Resolve (btw. nice usage of .NET 3.5 &lt;a href="http://msdn.microsoft.com/en-us/library/bb397696.aspx"&gt;anonymous types&lt;/a&gt;). I hope you see the power and simplicity that it brings.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s still a functionality that you couldn&amp;rsquo;t implement in few hours, and not the thing that made me writing this post. Light bulb started going over my head when I saw something like this:&lt;/p&gt;
&lt;h3&gt;Intercepting method invocation&lt;/h3&gt;
&lt;pre class="brush: csharp;"&gt;public class PerformanceLogger : IInterceptor
{
    public ILogger logger { get; set; }

    public void Intercept(IInvocation invocation)
    {
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        invocation.Proceed();
        stopwatch.Stop();
        logger.Log(string.Format(
            "Invocation of '{0}' took {1}ms.",
            invocation.Method.Name,
            stopwatch.ElapsedMilliseconds
        ));
    }
}

public static void Main()
{
    // Configuration
    WindsorContainer container = new WindsorContainer();
    container.Register(Component.For&amp;lt;ILogger&amp;gt;().ImplementedBy&amp;lt;ConsoleLogger&amp;gt;());
    container.Register(
        Component.For&amp;lt;IProductionClass&amp;gt;()
        // Only new line
        &lt;strong&gt;.Interceptors(new InterceptorReference(typeof(PerformanceLogger))).Anywhere&lt;/strong&gt;
        .ImplementedBy&amp;lt;ProductionClass&amp;gt;());
    container.Register(Component.For&amp;lt;PerformanceLogger&amp;gt;());

    // Usage (still the same!)
    IProductionClass productionClass = container.Resolve&amp;lt;IProductionClass&amp;gt;(
        new { Name = "MyProductionClass" }
    );

    productionClass.DoWork();

    // Output
    // "MyProductionClass: DoWork"
    // "Invocation of 'DoWork' took 271ms."
}&lt;/pre&gt;
&lt;p&gt;There is a possibility in Windsor to intercept method invocations (do &lt;a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming"&gt;AOP&lt;/a&gt; basically) to, for example, check permissions, log something, add error handling. Above example introduces new class PerformanceLogger which implements Windsor&amp;rsquo;s IInterceptor interface. Only thing to make it intercept method invocations is to add it to registration of given component!&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;I hope I&amp;rsquo;m getting better at writing posts, and that with this one I interested you in IoC containers and encourage you to try it yourself. As you could hopefully see, IoC can help make your applications be easier and simpler.&lt;/p&gt;
&lt;h3&gt;Post Scriptum&lt;/h3&gt;
&lt;p&gt;There is a possibility to skip configuration step in Windsor. You can for example write something like that:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;container.Register(
    AllTypes.FromAssemblyNamed("MyServicesImplementations")
    .Where(t =&amp;gt; t.Name.EndsWith("Service"))
    .WithService.FirstInterface());&lt;/pre&gt;
&lt;p&gt;Now you even don&amp;rsquo;t have to configure new component/service to work. You can just put ISomeService and SomeService class somewhere and start using them!&lt;/p&gt;</summary>
    <published>2009-11-16T20:13:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2009/11/16/Introduction-to-Inverson-of-Control-magic.aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=a6ef3f13-ab08-44fb-97d9-4798c4566a6a</pingback:target>
    <slash:comments>50</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=a6ef3f13-ab08-44fb-97d9-4798c4566a6a</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2009/11/16/Introduction-to-Inverson-of-Control-magic.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=a6ef3f13-ab08-44fb-97d9-4798c4566a6a</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2009/09/09/Bugs-in-Visual-Studio-2008.aspx</id>
    <title>Bugs in Visual Studio 2008</title>
    <updated>2009-09-09T21:59:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=974f9f31-7260-4e36-8fe1-08d4becc7520" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2009/09/09/Bugs-in-Visual-Studio-2008.aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;p&gt;Like I said in previous posts, there is no software without bugs. But still I was quite surprised when I have found my first bug in Visual Studio. And now I know even two:).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://support.microsoft.com/default.aspx/kb/960075" target="_blank"&gt;Undocking windows while debugging crashes Visual Studio&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=367121" target="_blank"&gt;Debugging unit test with option &amp;ldquo;Enable .NET Framework source stepping&amp;rdquo; crashes Visual Studio&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Those aren&amp;rsquo;t the only bugs in Visual Studio, just try to search for them in Google.&lt;/p&gt;
&lt;p&gt;I even fought few times that some behavior of VS, C# compiler especially, is a bug, when it wasn&amp;rsquo;t. For example:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public enum MyEnum
{
    One,
    Two,
    Three,
}

Person person = new Person { FirstName = "John", LastName = "Wayne", };&lt;/pre&gt;
&lt;p&gt;Did you noticed that last comma in enumeration definition and in object initializer? C# specification allows those odd commas to simplify life of code generation tools!&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public static bool Compare(object x, object y)
{
    return x.Equals(y);
}

int static Main(string[] args)
{
    int x = 1;
    Console.WriteLine(Compare(x, x));
}&lt;/pre&gt;
&lt;p&gt;This code will print &amp;ldquo;false&amp;rdquo;. Maybe you know why? (answer is connected with english Christmas;)&lt;/p&gt;</summary>
    <published>2009-09-09T21:59:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2009/09/09/Bugs-in-Visual-Studio-2008.aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=974f9f31-7260-4e36-8fe1-08d4becc7520</pingback:target>
    <slash:comments>7</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=974f9f31-7260-4e36-8fe1-08d4becc7520</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2009/09/09/Bugs-in-Visual-Studio-2008.aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=974f9f31-7260-4e36-8fe1-08d4becc7520</wfw:commentRss>
  </entry>
  <entry>
    <id>http://dotnet.uni.lodz.pl/whut/post/2009/09/08/Bug-less).aspx</id>
    <title>Bug-less:)</title>
    <updated>2009-09-08T19:20:00+00:00</updated>
    <link rel="self" href="http://dotnet.uni.lodz.pl/whut/post.aspx?id=0580175f-2cc9-4840-8745-5578441f9bf0" />
    <link href="http://dotnet.uni.lodz.pl/whut/post/2009/09/08/Bug-less).aspx" />
    <author>
      <name>Whut</name>
    </author>
    <summary type="html">&lt;p&gt;It quite scary when you notice that every program have bugs.&lt;/p&gt;
&lt;p&gt;How often are you sure that everything is OK? Till lately I was sure about that right after I put my fingers off the keyboard. Although I knew that nothing is perfect, I was thinking: &amp;ldquo;I wrote so great piece of software and thought about everything. It's so simple&amp;rsquo;. But then code went to production and people started to use it. Factors, like network problems, misbehaving users;), inconsistent or invalid data revealed tons of tons of bugs.&lt;/p&gt;
&lt;p&gt;So what to do? There are some options that I know so far:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;unit testing &lt;/li&gt;
&lt;li&gt;integration tests &lt;/li&gt;
&lt;li&gt;static code analysis &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unit tests?&lt;/h3&gt;
&lt;p&gt;They are great for documenting your API:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;[TestMethod]
public void Test()
{
    // Arrange
    Database database = new Database();
    int nonExistingPersonId = 12345;

    // Act
    Person person = database.Get&amp;lt;Person&amp;gt;(nonExistingPersonId);

    // Assert
    Assert.IsNull(person);
}&lt;/pre&gt;
&lt;p&gt;From example above I see that Get method returns null when you try to find non existing person, and I&amp;rsquo;m sure that this behavior won't change unnoticeably (e. g. to throwing exception).&lt;/p&gt;
&lt;h3&gt;Integration tests?&lt;/h3&gt;
&lt;p&gt;Can you predict how user or other application will break your software?&lt;/p&gt;
&lt;h3&gt;Static code analysis?&lt;/h3&gt;
&lt;p&gt;Yeah, it will tell you that you left unused method or use some not-so-good coding practice.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;I will definitely use more often above practices and encourage others to do so. Maybe it&amp;rsquo;s also time for some continuous integration? And from different box: code reviews, team discussions, presentations, basically exchanging knowledge and building craftsmanship.&lt;/p&gt;
&lt;p&gt;But still my code will contain bugs! In spite of all the null checks, try/catch blocks and tests, professional atmosphere and prepared failover scenarios. And it will contain them whatever I will do:)&lt;/p&gt;</summary>
    <published>2009-09-08T19:20:00+00:00</published>
    <link rel="related" href="http://dotnet.uni.lodz.pl/whut/post/2009/09/08/Bug-less).aspx#comment" />
    <dc:publisher>Whut</dc:publisher>
    <pingback:server>http://dotnet.uni.lodz.pl/whut/pingback.axd</pingback:server>
    <pingback:target>http://dotnet.uni.lodz.pl/whut/post.aspx?id=0580175f-2cc9-4840-8745-5578441f9bf0</pingback:target>
    <slash:comments>7</slash:comments>
    <trackback:ping>http://dotnet.uni.lodz.pl/whut/trackback.axd?id=0580175f-2cc9-4840-8745-5578441f9bf0</trackback:ping>
    <wfw:comment>http://dotnet.uni.lodz.pl/whut/post/2009/09/08/Bug-less).aspx#comment</wfw:comment>
    <wfw:commentRss>http://dotnet.uni.lodz.pl/whut/syndication.axd?post=0580175f-2cc9-4840-8745-5578441f9bf0</wfw:commentRss>
  </entry>
</feed>