After a great start to the new year, I've taken the first three days back at work as PD days to catch up on a few things I've been missing out on. I've had to push my learning curve to the limit, but I've managed to cover off quite a few topics and summarise it all into one not-so-short post.

The gold resource for the week has been the new VS2008 Training Kit that includes a set of presentations, hands-on labs and demos. The presentations I've looked at haven't been much of a help to me at all, but the hands-on labs and demos have been key to me while learning about these technologies.

The first topic I was concerned with was the new features of C# 3.0 and .Net 3.5. I've heard and seen a lot about them, but I've never had a chance to sit down and get to know them. The What's New in C# 3.0 lab in the training kit covers these topics and gives an excellent introduction to how to use them. It takes about an hour to work through an introduces the following concepts:

  • automatically implemented properties - public int CustomerID { get; private set; }
  • object and collection initialisers - Customer c = new Customer { Name = "John", Location = "London" }
  • implicitly typed local variables and arrays - var complexList = new SortedDictionary<string, List<DateTime>>()
  • extension methods - public static List<T> Append(this List<T> a, List<T> b) { ... }
  • lambda expressions - customerList.FindAll( c => c.Location == "London");
  • expression trees - Expression<Func<int, int>> addOneExpression = n => n + 1;
  • anonymous types - var customer = new { Name = "John", Location = "London" };

Next up was AJAX. I've had some experience in the past with very very very early AJAX (i.e. XmlHttp... :-)) and know about how it all works, but I've never had the chance to put together a website that utilises it. Once again, the training kit labs came in very handy here. The Introduction to ASP.NET AJAX lab was a great introduction to implementing an the ScirptManager and UpdatePanel controls in an existing website to add AJAX functionality and introduced other concepts such as connecting to WCF services from JavaScript, using LINQ data sources and the AJAX Control Toolkit. The second lab on the topic was Building AJAX/JSON Services Using WCF, which showed the power of the combination of AJAX and JSON. However, I think it was a bit confusing in that it utilised the AJAX Control Toolkit too much. I would have liked to actually see some JSON strings flying around. :-)

I've also been concentrating some effort on the new ASP.NET 3.5 Extensions. If you haven't heard about it before, it's basically a collection of toolkits that new functionality being added to ASP.NET 3.5 and ADO.NET in 2008. These functions include:

  • ASP.NET Dynamic Data
  • New additions to ASP.NET AJAX
  • ADO.NET Entity Framework
  • ADO.NET Data Services
  • Silverlight Controls for ASP.NET

The download website has a few videos on it introducing all of these functions along with a link to the quickstarts that do a great job of diving deeper. I actually used ScottGu's blog more... :)

The area I've concentrated on is the MVC. I started by going through the a few posts ScottGu made a little while back (all in this post). These are an excellent starting point for someone wanting to get their hands dirty. However, there are a few small issues with some of the code that is probably due to it's pre-release nature (or Works on My Computer syndrome :-)). The major issue was that controls on an MVC content page are not accessible in the code-behind. You'll see this if you follow the sample in Scott's Part 1 blog post and try to render the Category list using a ListView control because when it comes time to set the list's data source there is no list in Intellisense. Also, the TestViewEngie class mentioned when developing tests for the controller using an IViewFactory is not available in the MVC framework. Phil Haack has blogged some excellent methods for TDD with DI and Testing Routes using Rhino Mocks and StructureMap.

One thing to watch out for in URL routing is that the routes are taken in the order they are created. For example, in Scott's walk through he mentions tweaking the routing rules to add the ability to route /Products/List/Beverages to pass the category to the List action in the Products controller. This would be done easily by adding the following route code to the Global.asax file's Application_Start event handler:

RouteTable.Routes.Add(new Route
    Url = "/Products/List/[category]"
    Defaults = new { controller = "Products", action = "List", category = (string)null },
    RouteHandler = typeof(MvcRouteHandler)

I added this under the "/[controller]/[action]/[id]" and whenever I went go to /Products/List/Beverages I would receive an error because the category parameter for the List action was null. Moving the route to the top of the method (i.e. so that it is the first added to the list) fixed this. This behaviour is mentioned in the quickstarts:

"The order in which Route objects appears in the Routes collection is significant. Route matching occurs from the first route to the last route in the collection. When a match occurs, no more routes are evaluated. Typically the default route will be the last route."

By the way, I really suggest watching the video on Dynamic Data available on the download website because it just rocks! It's very simple and very powerful. When you first run a project it builds all the controls and pages requires by the data model. It then allows you to easily extend your data model by using partial methods and add validation and rendering hints using attributes on partial classes. You can also go through and modify all the generated pages. Definitely one of the next stops on my PD roadmap... :-) Once again, Scott's got good blog post with a walk-through and some excellent links.

I'm going to finish off on a cool little download I found the other day. It's a two page poster of some of the most useful default key bindings (i.e. keyboard shortcuts) available in C# with Visual Studio 2008 available at the Microsoft Download Centre.