First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)

December 2009 Blog Posts

Best of 2009: the 5 most popular posts

The end of the year is approaching and it’s time for a recap on what happened during the last 12 months. As I did in 2008 I blogged a lot about ASP.NET MVC (around 40 posts) and few about jQuery (just 6 posts), but unlike last year where the most popular posts were about jQuery, this year it’s all ASP.NET MVC. Probably that’s because the technology is more mature than it was during 2008.

The most popular posts of 2009

1. 13 ASP.NET MVC extensibility points you have to know – This post goes through all the extensibility points that are important to understand if you want to fully exploit the ASP.NET MVC framework

2. 12 ASP.NET MVC Best Practices – A list of some best practices for developing good asp.net mvc applications. This is the content of a presentation I held in October at the Gladiator Fest in Rome.

3. How to create a DropDownList with ASP.NET MVC – Building a dropdown list in ASP.NET MVC requires a different approach from what you were used with WebForms, but also differs from the other HtmlHelpers: this post explains how to use the DropDownList HtmlHelper

4. How to use Ninject with ASP.NET MVC – Ninject comes with a sister project that helps registering controllers inside Ninject’s Kernel: this post is the first of series of 5 posts that explain how to use Ninject inside ASP.NET MVC. This post was about Ninject v1. Later in the year I also wrote a post about Ninject v2.

5. How to improve the performance of ASP.NET MVC web applications – This was written in response to another post that showed how to improve the performance of ASP.NET MVC applications. My point was: caching data is the best performance optimization you can do.

Looking at the posts from 6-10 there are other 3 posts about ASP.NET MVC (my stack, how to use Ninject 2 with ASP.NET MVC and one with some suggestions for RoR developers that what to start using the MVC framework by MS), one about Lucene.net and one about jQuery and Ajax.

And what about the most popular of all time?

Since I skipped the usual blog-versary post I also want to quickly list the top 10 posts since I started blogging.

  1. How to make a Gmail-like loading indicator with ASP.NET Ajax (67376 views)
  2. How to refresh an UpdatePanel from javascript (65561 views)
  3. Ajax TreeView (40261 views)
  4. How to manage ASP.NET validation from Javascript with jQuery (33433 views)
  5. Milan l'é semper Milan (30082 views)
  6. How to add a required validator to a CheckBoxList (25876 views)
  7. Rss2BlogML: export any RSS feed to a BlogML file (20688 views)
  8. .NET Ajax Survey results (18940 views)
  9. 13 ASP.NET MVC extensibility points you have to know (16454 views)
  10. The book writing process (15064 views)

The top spots didn’t chance since last year but it’s nice to see that one post I wrote this year already made the top 10 of all time.

How 2009 was different from 2008

In 2009 I posted 110 posts, almost 40% less posts than 2008 (where I wrote 183 posts). And on the traffic side, it grew by almost 50%, going from 250k views to 370k views. Also the number of subscribers grew, going from the 1000 RSS subscribers of the end of 2008, to the almost 2400 RSS subscribers of today.

What’s going to happen in 2010?

Since I started using Twitter the types of blog posts change from what it used it be in the past years: personal and quick thoughts are now on Twitter, and only technical posts make it to the blog. And I expect next year to be the same: I’ll post more about ASP.NET MVC, more about Subtext and everything that I come across during my future projects.

If you haven’t already, consider subscribing to my free updates via RSS

kick it on DotNetKicks.com

Merry Christmas and Happy New Year from CodeClimber

Print

This 2009 has been in important year in my career, more on the community than in the real day-time work side of things, but I’ll come on this later. For now, I just want to send to my almost 2400 readers my best wishes for a

Merry Christmas and an Happy New Year

ASP.NET MVC ControllerFactory for Unity and the reasoning behind it

Most of the mainstream IoC containers have their own implementation of a custom controller factory for ASP.NET MVC, but Unity doesn’t. There is an implementation in the MvcContrib project, but I don’t like the way it works, so I decided to implement it myself.

Unity Controller Factory

After a few mail exchanges with a guys of the p&p team and with Brad Wilson I came out with the following 35 lines of code.

public class UnityControllerFactory: DefaultControllerFactory
{
    protected override IController GetControllerInstance(Type controllerType)
    {
        IController controller;
        if (controllerType == null)
            throw new HttpException(
                    404, String.Format(
                     "The controller for path '{0}' could not be found" +
			"or it does not implement IController.",
                     this.RequestContext.HttpContext.Request.Path));
        if (!typeof(IController).IsAssignableFrom(controllerType))
            throw new ArgumentException(
                    string.Format(
                        "Type requested is not a controller: {0}",
                        controllerType.Name),
                        "controllerType");
        try
        {
            controller = MvcUnityContainer.Container.Resolve(controllerType)
                            as IController;
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException(String.Format(
                                    "Error resolving controller {0}",
                                    controllerType.Name),ex);
        }
        return controller;
    }
}

public static class MvcUnityContainer
{
    public static UnityContainer Container { get; set; }
}

And the only things needed to use it is creating the container, passing it to the controller factory, registering the dependencies (repositories, services) and finally setting the custom controller factory.

//Create UnityContainer
UnityContainer container = new UnityContainer();

//Configure container
container.RegisterType<IFrontendService, FrontendService>();
container.RegisterType<IDateTimeProvider, DateTimeProvider>();
container.RegisterType<IFrontendDataAccess, SqlFrontendDataAccess>();

//Set container for Controller Factory
MvcUnityContainer.Container = container;

//Set for Controller Factory
ControllerBuilder.Current.SetControllerFactory(
                    typeof(UnityControllerFactory));

Implementation possibilities

There are two possibilities when you want to write a custom controller factory:

  • Implement IControllerFactory and implement the CreateContoller method that returns a controller based on the controller name
  • Inherit from DefaultControllerFactory and override GetControllerInstance which returns a controller based on the type that is needed

The first gives you complete freedom on the naming conventions of your controllers, but has two downsides: first it needs you to register not only the external references but also the controllers (container.RegisterType<IController, HomeController>("Home")). Second you also have to implement the logic to discover the correct controller based on the namespace and, more importantly with MVC v2, with the Areas.

The second approach delegates to the default implementation the mapping of the controller name to the type of the controller. Less freedom with the naming convention, but also less code to write both in the controller factory and also during the setup of your application.

Applying the same concept to Ninject

I think the Ninject controller factory uses the first approach and might not work with Areas in MVC v2, so I think I’ll submit a patch to adopt this easier approach.

Everybody stand-up! 7 resources for standup meetings

Standing up an hour or so after the day starts is one of the (first?) changes I’m trying to introduce into the team I’m working with now. Well, not just standing up around a water cooler, but also talking about what everyone did yesterday, what everyone is going to do today, and if there are some blocking issue that are preventing work to proceed correctly. This is not something I invented, it’s called “Standup Meeting” and is one of the first steps for introducing some kind of Agile into a team.

There is a lot of literature around that specific practice so I won’t explain here what a Stand up meeting is, but I’ll just point you to other links I found interesting.

We have introduced this new practice into the team only 2 weeks ago, and so far the things are going fine. The biggest benefit is that now people have an official moment in time to talk about blocking issues, while previously it was more difficult to try and get the attention of the team.

Let’s see how this turns out in a month or so.