A few posts back I listed goals I wished to achieve over the next six months. Currently I am looking in to the Microsoft MVC Framework. I have started by watching Scott Hanselmans' four screen casts over at www.asp.net, these give a pretty good introduction of the framework and what you get out of the box with Visual Studio 2008 with the MVC framework extensions installed. There is also a screen cast from MIX08 here which covers most of the same material, but works as a once over refresher. Jeff Palermo also has a good demonstration on dnrTV. I have found in the past that it is easier to learn about something if you have a set of questions to ask, the natural process of researching the answers leads to a better understanding of the subject matter. So here are a few simple questions I have asked myself.
Some q and a's on MVC
1. Why bother with MVC?
If you are developing large enterprise web applications which rely a lot on view state, do not use MVC. If however you are developing a relatively small web application, perhaps a social network type application, then MVC may be for you. However you can mix and match by implementing MVC within an asp.net web application. Also if you are wanting to develop web applications using a TDD approach, then it may help you as unit testing is fully supported.
2. Does it get rid of the dreadful post-back?
Yes. The ASP.Net MVC framework does not implement post-back, view state or use the web forms event driven lifecycle. This will be a relief to some people, however if you want to store any temporary data between page requests, you need to find another mechanism to do so.
3. What is REST?
REST stands for REpresentational State Transfer and is a mechanism to transfer data via HTTP without utilising any messaging layers such as sessions or cookies. REST applications are generally Client-server, Stateless, Cacheable, and Layered. It can use the HTTP methods of POST, GET, PUT and DELETE to perform the basic CRUD commands for data manipulation. So a URL of /blogs/GET/today can represent a command to retrieve blogs updated today. Microsoft MVC uses a technique called routing which can basically replace the URL above to something more user friendly such as /blogs/show/today.
4. Is it a pattern or a framework?
MVC is a pattern, is well documented and has in fact been around since at least the early 80's. ASP.Net MVC is a framework developed solely for asp.net from Microsoft.
5. Do I still need AJAX, if so how?
ASP.Net MVC works with or without AJAX so implementing AJAX is entirely up to the developer. When the product goes to RTM it will fully support the Microsoft ASP.Net AJAX out of the box, however the developer is free to use any other AJAX framework. Nikhil Kothari has an excellent article where he delves in to MVC Ajax in more detail.
6. Is it just for .net 3.5 or can I use it for 2.0?
The ASP.Net MVC is currently only supported on 3.5. In Visual Studio 2008, selecting a new project in 3.5 gives you the choice to create an ASP.Net MVC project with or without an additional unit test project.
7. Can I run it on IIS6 or is it for IIS7?
You have two options when running it on IIS6, you can either use a wildcard mapping to the asp.net isapi dll or you can map the .mvc extension to it. The former will impact performance of the website, the latter will give less desirable URL including a .mvc extension in the URL. You can employ a rewriter dll such as isapi_rewrite as described here.
Asking myself these simple questions has given me the opportunity to look in to MVC and I have cleared up some of my own perceptions of the whole MVC thing. It has also given me more questions to research such as how to store tempory data without using session or cookies. I hope to expand on these questions in future posts.
My next step is to install the thing and have a good play around with it.
Very basic I know, but it has helped me and it may help someone else.
Here are some links to sites which I have found useful.
Introduction to REST
http://www.viddler.com/Roebot/videos/10/
A Brief Introduction to REST
http://www.infoq.com/articles/rest-introduction
Chapter 4. What is MVC?
http://www.jcorporate.com/expresso/doc/edg/edg_WhatIsMVC.html
Model-View-Controller
http://www.webopedia.com/TERM/M/Model_View_Controller.html
MVC Overview
http://quickstarts.asp.net/3-5-extensions/mvc/MVCOverview.aspx
We have finally finished our migration to SQL 2005 at the weekend. That is 2 migrations to Windows 2003 and 2 migrations to SQL 2005 as well as upgrading our main accounting package. We started on Friday evening, did the main work during Saturday and the testing Sunday, so everyone here is a bit tired now. We have not been able to undertake any development work for the past 2 months because of this upgrade, but now it is over I can get back to what I love; writing code. This lead me to wonder with all the new technology coming out of MS at the moment, what are other peoples stance with older but still useful projects. Do you re-write the old Intranet to encompass Linq etc...
As I have grown as a developer I sometimes look at my old code, shudder and think 'Why did I do it that way, this other way would have been much better.' There is such a difference as to how I code now and how I did just 3 years ago. Do you take the stance of 'If it isn't broke, don't fix it' or do you attempt to get all projects using the same technologies/methodologies, basically singing from the same hymn sheet.
When I started at my current place I wrote a fantastic (well I think) customer facing reporting suite. It runs with hardly any problems, but now I hate the code base so much and would love to re-write it. Should I bother?
It has been a few weeks since my last post, so apologies for that. I have finally passed MS exams 70-292 and 70-296 so I am now an MCSE on Windows Server 2003 at last; hence the disappearing act.
Readers of my previous post and also my old blog will know I have been working with Nant and Subversion over the past few months. Well the time has finally come to marry them together in to a CI system. I have installed and configured CCNet which will monitor SVN and check out files if there has been any changes. The nant build scripts are then automatically called each time to perform a nice clean build. I won't discuss the installation of CCNet as it is pretty straight forward, what I will concentrate on here is the ccnet.config file which is where project configuration is held. Here is a very basic example.
<cruisecontrol>
<project name="testCCNet">
<workingDirectory>C:/Projects/testCCNet/testCCNet/
</workingDirectory>
<triggers>
<intervalTrigger seconds="60" />
</triggers>
<modificationDelaySeconds>10</modificationDelaySeconds>
<sourcecontrol type="svn">
<executable>C:/SVN/bin/svn.exe</executable>
<trunkUrl>svn://192.168.255.116/code/testCCNet/trunk/testCCNet
</trunkUrl>
<autoGetSource>true</autoGetSource>
<workingDirectory>C:/Projects/testCCNet/</workingDirectory>
</sourcecontrol>
<tasks>
<nant>
<executable>C:/Program Files/NAnt/bin/nant.exe</executable>
<nologo>false</nologo>
<baseDirectory>C:/Projects/testCCNet/testCCNet/
</baseDirectory>
<buildFile>nant.build</buildFile>
<buildTimeoutSeconds>600</buildTimeoutSeconds>
</nant>
</tasks>
</project>
</cruisecontrol>
Some things to note:
Notice the forward slash within the directory paths. If you don't know XML then the \ character is illegal within elements, there are three ways around this.
1. Switch it to a forward slash like above
2. Use double back slashes (\\)
3. Enclose the path within <![CDATA[...]]> tags. This tells the XML parser that it is un-parsed character data.
The above script basically checks svn for any updates every 60 seconds. If an update is found then it calls nant using nant.build as the build file. If you don't want to check every 60 seconds and only run a build at 6am then replace the element with this.
<scheduleTrigger time="06:00" buildCondition="ForceBuild" />
You can of course mix and match both intervalTrigger and scheduleTrigger.
If you are building quite a large application, be careful it does not exceed the buildTimeoutSeconds.
The modificationDelaySeconds element specifies how long in seconds since the last check in before attempting to run a build. This is to prevent a build running if a user is part way through committing updates to the source control.
When you install CCNet it creates a desktop shortcut to ccnet.exe. When you have this running, you can keep track of which projects build successfully and which ones don't. If you do not want this running visually or are worried you will not start it up if you reboot the CI machine, then one possibility is to use a utility like System Scheduler from Splinterware. This tool will start up the ccnet.exe application on start up and run it in the background.
Also during install, a virtual directory called ccnet is added to the machines default website (if you have IIS installed). So browsing to http://localhost/ccnet/ViewFarmReport.aspx will give you reports and stats on the status of your various projects.

If you get errors when first loading this page, check what asp.net version the ccnet virtual directory is running under.