Tuesday, June 3, 2008

Great resource: Rob Conery's MVC screencasts.

In the past couple days I found a great series of blog posts/screencasts. They are from Rob Conery and he is posting an attempt he is making step-by-step to implement a website using the ASP.Net MVC structure with Test Driven Development.

I found it very interesting to watch him go through this. It is quite a nice break from the typical Microsoft demos which seem to be a little more marketing and less real world experience.

It is also interesting to see him code something in a different way than I might and to see how things unfold. I guess you could call it one way pair programming.

Anyway, I would suggest checking it out. Here is a link to his first post in the series:
http://blog.wekeroad.com/mvc-storefront/mvc-storefront-part-1/

And here is the list of posts in the category he has set up in his blog. You'll have to navigate back in this list to find the earlier posts:
http://blog.wekeroad.com/mvc-storefront/

I think one of the most interesting ideas I've picked up from his posts so far is the way he is composing filters using the IQueryable<> interface. For example in his data access layer, he has a method called GetCategories() that returns IQueryable. Then instead of adding a separate method to get a category by an id number, like GetCategory(int id), he creates an extension method, .WithId(int id) that extends IQueryable so the full call looks something like:
Category c = dataLayer.GetCategories().WithId(4);

And, because LINQ only executes queries when needed and these filters are part of the expression tree, the filters are reflected in the actual query that hits the database. In this example only the category with id = 4 is pulled back -- the filtering is done at the query level.

It is a very interesting approach. It cleans up the LINQ code a bit and makes it quite readable. I'll have to fool around with the idea in my own code to see how I like it. You can see some of the filter code here.

If you have some time and you are interested in the ASP.Net MVC project and test driven development/design, I would highly suggest watching his videos.

No comments: