About sublime text 2

Another great text editor, free to everyone, but you can contribute to the project by paying for the license.

sublime text 2: http://www.sublimetext.com/2

sublime packages

By installing sublime package control, you can benefit from diverse plugins.

package control installation: http://wbond.net/sublime_packages/package_control/installation

List of community packages: http://wbond.net/sublime_packages/community

List of packages I use

Setting up build system

By setting up the build, you can easily run javascript tests or build sass.

Go to Tools -> Build System -> New Build System, and add your own build script. For example, mine is like this.


    "cmd": ["cmd.exe", "/c", "rake", "run_jstests", "build_section=files"],
    "working_dir": "YOUR_WORKING_DIRECTORY",
    "selector": "source.js"


You can look at the comprehensive keyboard shortcuts, yet the below are my favourites.

  • open console: ctrl + ‘
  • open command pallete: ctrl + shift + p
  • find in files: ctrl + shft + F
  • reveal in sidebar: unfortunately, no shortcut key yet. right on the view and select it
  • Quick-open files by name: ctrl + p
  • Go to word in the current file: ctrl + ;
  • Duplicate line(s): ctrl + shft + d
  • move line/selection up: ctrl + shft + up arrow
  • move line/selection down: ctrl + shft + down arrow
  • align variables declaration (alignment): ctrl + alt + a

About Castle Windsor Container

Since I moved to Huddle, I am using Castle Windsor. This post is the summary of what I would learn while using Castle Windsor.

the source code

I don’t know why, but I found it difficult to find where the code is. It is here at https://github.com/castleproject. Even there is a stackoverflow question about where the code is.

Very descriptive error message

I often struggled with StructureMap error message, as it doesn’t tell you what went wrong. I like Windor’s, as it clearly states where it is screwed.

Can’t create component ‘LondonUbf.Installers.LoggerInterceptor’ as it has dependencies to be satisfied.

‘LondonUbf.Installers.LoggerInterceptor’ is waiting for the following dependencies:
– Service ‘LondonUbf.Domain.ExceptionLogger’ which was not registered.


There are a few tutorials. The link was in readme file of the project.

Use of Predicate

By the way, an example code in the tutorial uses Predicate, and it is interesting. I knew they exists, but didn’t really use it in my day-to-day coding.

public void All_Controllers_Are_Registered()
    var allControllers = GetPublicClassesFromAssembly(c => c.Is<IController>());
    var registeredControllers = GetImplementaionTypesFor(typeof (IController), _containerWithControllers);
 Assert.That(allControllers, Is.EqualTo(registeredControllers));
private Type[] GetPublicClassesFromAssembly(Predicate<Type> where)
    return typeof (HomeController).Assembly.GetExportedTypes()
        .Where(t => t.IsClass)
        .Where(t => t.IsAbstract == false)
        .OrderBy(t => t.Name)

By accepting Predicate parameter, you can make the method to accept lamda filter. This is the source of Predicate. It is delegate that returns boolean value.

namespace System
    /// <summary>
    /// Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.
    /// </summary>
    /// <returns>
    /// true if <paramref name="obj"/> meets the criteria defined within the method represented by this delegate; otherwise, false.
    /// </returns>
    /// <param name="obj">The object to compare against the criteria defined within the method represented by this delegate.</param><typeparam name="T">The type of the object to compare.This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived. For more information about covariance and contravariance, see Covariance and Contravariance in Generics.</typeparam><filterpriority>2</filterpriority>
    public delegate bool Predicate<in T>(T obj);

Registering interfaces

Not much different from other IoC containers like Ninject and StructureMap.

public class RepositoriesInstaller : IWindsorInstaller
    public void Install(IWindsorContainer container, IConfigurationStore store)
        container.Register(Component.For<FileNameParser, IMessageParser>());
            Component.For<MessageRepository, IMessageRepository>()
            .DependsOn(new { messageDirectory = HostingEnvironment.MapPath("/Content/messages")})

If your class depends on any other variable, you can use .DependsOn to resolve it. In the above example, I used HostingEnvironment.MapPath to find out the directory of “messages”. It doesn’t require HttpContext, unlike Server.MapPath(…).

cf) The difference betweeen Server.MapPath and HostingEnvironment.MapPath(…): http://stackoverflow.com/questions/944219/what-is-the-difference-between-server-mappath-and-hostingenvironment-mappath

Dynamic Proxy

where T: class, new()

It is a constraint on the generic parameter that T must be a class and have an parameterless default constructor. (from Stackoverflow)

The DP tutorial example used this syntax.

public static TFreezable MakeFreezable<TFreezable>() where TFreezable : class, new()
    var freezableInterceptor = new FreezableInterceptor();
    var proxy = _generator.CreateClassProxy<TFreezable>(new CallLoggingInterceptor(), freezableInterceptor);
    _freezables.Add(proxy, freezableInterceptor);
    return proxy;

It is surprisingly simple to intercept a call to method. Just add .Interceptors() to the component registration.

    Component.For<MessageRepository, IMessageRepository>()
    .DependsOn(new { messageDirectory = HostingEnvironment.MapPath("/Content/messages")})

The interceptor is a simple class.

public class MessageRepositoryInterceptor : IInterceptor
    private readonly ExceptionLogger _logger;

    public MessageRepositoryInterceptor(ExceptionLogger logger)
        _logger = logger;

    public void Intercept(IInvocation invocation)
            _logger.Log(string.Format("{0}.{1},  Message: {2} ", invocation.TargetType.Name, invocation.Method.Name, invocation.Arguments[0]));
        catch(Exception ex)

the Life cycle of objects

Quite bluntly saying, if you inject your dependencies into constructor of a class, those dependent objects are disposed together when the class gets disposed. However, if you use resolve a dependency manually, using .Resolve(), you have to release it manually.