hotrannam's corner

I make software

HTML5 Programming

leave a comment »

Written by Nam

January 5, 2012 at 10:48 am

Posted in HTML5

Tagged with

Here’s to the crazy one – Steve Jobs

leave a comment »

Written by Nam

October 7, 2011 at 10:24 pm

Posted in Life

My presentation at BarCamp Saigon Summer 2011

leave a comment »

Written by Nam

July 25, 2011 at 2:00 pm

Posted in Node.js

Tagged with , ,

Tết

leave a comment »

Nam nhi tự hữu xung thiên chí
Hưu hướng Như Lai hành xứ hành

Thiền sư Quảng Nghiêm [1122-1190]

Written by Nam

February 3, 2011 at 9:43 pm

Posted in Life

Tagged with

Multi tenancy

leave a comment »

My lightning talk about multi tenancy at ALT.NET Saigon.

Written by Nam

February 1, 2011 at 7:25 pm

Posted in Multi tenancy

Tagged with

ASP.NET MVC 3: Inversion of control

with one comment

This is the first post in the series that I am going to warm up my knowledge in ASP.NET MVC. I will pick the latest version, ASP.NET MVC 3 RTM. It is good for me to recall the old things and know the new things as well.

In the new features, I first try IoC improvements. Controller factory was extensibility point that I liked. This is where I could register external services that controllers need. It’s not only to resolve dependencies for controllers, more than that, thinking of chain of dependency. In ASP.NET MVC 3, controller factory is disappeared and the interface IDependencyResolver is introduced.

public class ServiceResolver : IDependencyResolver
{
    private IUnityContainer container;

    public ServiceResolver()
    {
        this.container = new UnityContainer();
        this.RegisterServices();
    }

    private void RegisterServices()
    {
        this.container.RegisterType<IFooService, FooService>();
    }

    public object GetService(Type serviceType)
    {
        try
        {
            return this.container.Resolve(serviceType);
        }
        catch
        {
            return null;
        }
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        try
        {
            return this.container.ResolveAll(serviceType);
        }
        catch
        {
            return new List<object>();
        }
    }
}

Once I have an instance that is implementation of this interface, I could set it as default resolver to inject dependencies into controllers.

protected void Application_Start()
{
    //...
    DependencyResolver.SetResolver(new ServiceResolver());
}

There is also an overload of static method DependencyResolver.SetResolver with parameter is Common Service Locator. It sounds cool, but I am not sure will use it.

It is trick to must have try/catch block in GetService method. Without this, ASP.NET MVC 3 will throw an error related to IControllerFactory. Oops, it is not disappeared totally.

Written by Nam

January 16, 2011 at 8:05 pm

Posted in ASP.NET MVC

Tagged with

My presentation at BarCamp Saigon 2010

with one comment

It’s my first attendance at BarCamp Saigon. It’s very impressed to meet and talk with some cool guys. I do hope there will be some events like this, especially for .NET developers community where everybody can come, learn and share. If you are interesting, please drop me a line.

Below are slides of my presentation on Ruby on Rails 3.

Written by Nam

December 14, 2010 at 10:52 pm

Posted in Ruby On Rails

Tagged with

Rails3: Getting started with a weird error

leave a comment »

I came across errors in installing rails with version 3.0.0 in today. The error message said that ‘mail requires i18n (~> 0.4.1, runtime)’. This is story of versions and it is not new in OSS at all. It has been discouraging who are not only beginners.

Some guys suggested installing i18n version 0.5.0 before rails. OK, it helps you get through the error. But wait, you will continue getting another error when creating a new rails application. Rails will complaint versions of gem i18n, 0.5.0 and 0.4.2. Some gems depend on 0.5.0 and others depend on 0.4.2.

Mail gem depends on version 0.5.0 of i18n. Taking a look at version of this gem, the version 2.2.11 is just updated in recent days, Nov 29, 2010. My experience in installing rails version 3.0.0 before had no these errors. I tried to install the previous version of mail gem, 2.2.10. I also checked version of dependencies at here. As you may see, the version 2.2.10 of mail gem requires version i18n gem greater than 0.4.1. So I thought choosing the version 0.4.2 of i18n will match requirement of other gems, and mail gem version 2.2.10 as well.

The following are steps to install.

  • gem install i18n -v=0.5.0
  • gem install rails -v=3.0.0
  • gem uninstall i18n (choose version 0.5.0 to uninstall)
  • gem uninstall mail
  • gem install mail -v=2.2.10
  • rails new hello_app

Hope this helps.

Written by Nam

December 4, 2010 at 4:03 pm

Posted in Ruby On Rails

Tagged with

Mom, I will try to keep it green

leave a comment »

again…

Written by Nam

August 20, 2010 at 11:22 pm

Posted in Uncategorized

Bill Gates, 1984

leave a comment »

“To create a new standard, it takes something that’s not just a little bit different, it takes something that’s really new and really captures people’s imagination and the Macintosh, of all the machines I’ve ever seen, is the only one that meets that standard.”

Microsoft founder Bill Gates, 1984

Written by Nam

July 12, 2009 at 3:42 pm

Posted in Inspiration

Tagged with

Follow

Get every new post delivered to your Inbox.