Foundations of Programming – Learning Application

If you’re anything like me, you probably learn a lot better by going through code rather than reading books. I’m happy to release the Foundations of Programming Learning Application – it’s a complete solution meant to show what was covered in the Foundations series. It’s a Visual Studio 2008 solution.

You can download it here. It should require no configuration (my fingers are crossed on that one) and ought to just run out of the box. There are comments sprinkled all over to help explain things or provide some insight. No doubt there’ll be typos, since I’m nothing without word.

(you can grab the free ebook from:

What is it?
It’s a sample awards website – with categories and nominees. The root container is called a Round – a sample Round would be called ‘The 2008 CodeBetter Awards’. A Round has a state (planning, annoucements, voting, winners) and a number of Categories (Best Blogger, Best Blog Post, Best Open Source Project, …) with each categories having a Nominee (Title, Summary, Link, Author…). The website is using the ASP.NET MVC Preview 4 – I don’t think you’ll need to install anything extra as all the DLLs are included with the project. I’m using an SQL Lite database with a relative path to the file, so all should work as-is. Dummy data is already loaded.

The web application mostly shows a read-only view of the data. There’s also a sample console application that does more administrative stuff (it isn’t interactive, it just runs through 4 steps or so). You can run the administrative portion over and over again – the first step is to clean itself up. The admin part basically adds a new round, with categories and nominees.

Of course, there’s a project full of unit tests as well.

I tried to keep everything simple and straightforward (which is largely why I didn’t want to build a whole web-based admin module and user registration and all that). Like most, I’m pretty new to ASP.NET MVC. Some might think my views have too much code, I think they have the perfect amount [:P]. There’s extensive use of Lambdas, so if you have a hard time reading them, I hope my excessive examples will help illuminate them.

This entry was posted in Foundations. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

18 Responses to Foundations of Programming – Learning Application

  1. Andy says:

    Karl, thank you for all the effort you put into this. Without mentoring it is difficult to try and get a thorough understanding of the concepts promoted by the Agile community but this has certainly helped.

  2. faffy fuck says:

    Hi Karl Pinguin, nice article!

  3. Giorgi says:


    First of all thank you for the sample and free e-book. They are simply great.

    Can you please also provide a winforms demo and demo (not mvc version) too? I believe many users (including me) would find it useful

    Thank you once again.

  4. Bob Baker says:

    Great book. Thank you!

    I’m having a strange error when running default.aspx for the first time — it crashes on the namespace add of System.Web.Mvc in web.,config. I had not touched anything as far as Copy Local or anything. Added the References folder to the web site properties to no avail. Ditto for Adding an Import to Site.Master. At that point, it gets a method not found on System.Web.Mvc.RouteCollectionExtensions.IgnoreRoute, even though I’m now explicitly typing the routes input param to RegisterRoutes in Global.asax.cs as a System.Web.Routing.RouteCollection. Was this sample app built for one of the Previews? I have MVC Beta 1 installed.

  5. Rik says:


    Just read the book and looked at the sample application – all the things I have been hearing about in the last few years, very well explained, especially the concept of domain-driven-design.

    Looking at your sample, you have as little logic as possible in the ascx file. I am currently working on a complex set of business requirements using a domain-centric approach.
    I have my aspx pages made up of various ascx controls to keep things simple and for reasons of re-use. Retrieving data to be displayed for each control is either looked up by the ascx file via linq and/or is mapped to a class structure specific for the ascx file. Data retrieved from the domain to be displayed is mapped to an ascx file class structure.

    Does this sound like the right way of doing things, or would you not have an ascx file retrieve any data directly, and if so, why? (The only reason I can think of is that maybe the web server is not allowed to access a database directly, but via another machine).


  6. karl says:

    Wrote a test, looks like you’re right. I continue to be amazed at how little I know, thanks…definitely good to know!

  7. Steve says:

    I have found this a very useful application to learn from. I am however unsure about a part of the round and other classes. In the round class you have the method “CategoriesChanged” and similar Changed methods in other classes. You state that is is required due to the ReadOnlyCollection acting as a cache so that it provides full List functionality while using IList for use by NHibernate which I can see the idea.

    But I cant seem to find a situation where it would actually be needed, from what I have tested and from reading the MSDN documentation I have the impression that the ReadOnlyCollection already reflects any changes made to the underlying list it wraps.

    If you could please correct me if I have missed something that makes this a valid method to use.

  8. DaRage says:

    It works now. Thanks karl.

  9. jdn says:

    No problem Karl.

    Just FYI, from home, I have the same issue, the zip file is corrupt when I download with IE, but works from other browsers.

    CodeBetter isn’t a download heavy site, but I remember this problem with CB a few years ago. I apologize that I don’t have a URL to a previous post, as I dont know if the problem was fixable (I download hundreds of files a month so there’s nothing inherently wrong with IE (well, about that anyway), it’s something about CB’s Community Server).

    To anyone else, if you have problems opening the sample app after downloading from IE, use a different browser.

  10. karl says:

    Well, if you look @ the sample admin module, you’ll see that we’re saving a round, 2 categories and a number of nominees with a single line in our NHibernateStore (GetSession.Save(round)). So I think you really can deal with a lot in a single datastore. The pattern I was thinking of was the table data gateway ( You can use it with an O/R mapper together.

  11. Adriaan says:

    Karl that makes perfect sense, thank you.

    I am trying to imagine how else would you handle IDataStore other than IXXXDataStore? How big(amount methods) can you take IDataStore, surely one can’t have all data acces methods in there for a large system or do you? What are the more advanced patterns you are referring to?

  12. karl says:

    Great questions. First, for such a small system, the benefits of the Repository class are certainly limited. The tradeoff between taking an example that’s easy to learn versus one that demonstrates the full capabilities. I have seen multiple implementations that had an IXXXDataStore per domain, and I didn’t like it. Unless it’s a really big system, I think it’s a code smell and you have a lot of duplication that can be rewritten. For such a system there are even more advanced patterns to help you out.

    The Repository and the DataStore serve two very distinct purposes (again, not all that obvious for such a slim application). For the Awards system, the API of one maps pretty closely to the API of another – so I see your confusion, why have both. I’ve worked on many projects where the repository does A LOT of things – caching, which I did here, interaction with web services, interaction with a legacy store, logging, and interaction with the data store. For the Awards site you could easily move the caching up into the domain or down into the NHibernate DataStore (especially given that NHibernate supports a 2nd level cache), and then remove the repository all together. But I think that before long, you’ll start to see code that really isn’t pertinent to the domain (it’s more plumbing than anything) and that isn’t tied to NHibernate or SQLLite.

  13. Adriaan says:

    You mentioned in the comments of the repository that in more complex systems one might use repository per class, does that mean you also going to need a more than one type of IDataStore?

    I am battling to see the purpose of IDataStore, why not have an NHibernate or SqlLite Repository?

  14. karl says:

    Looks like the ASP.NET MVC projects have their own ProjectTypeGuid. I changed the csproj files to use the default web application and it seems to work now even if you don’t have the ASP.NET MVC Preview installed. You mind redownloading and testing it again DaRage?

  15. DaRage says:

    The CodeBetter.Awards project didn’t open with VS2008. it complained about unsupported project type. All the other projects opened ok.

  16. karl says:

    If you’re having troubles downloading the file, I’ve also uploaded at:

    (thanks for letting me know about the problem jdn)

  17. jdn says:

    Yeah, it’s that old IE thing that happened with previous CodeBetter downloads. Firefox grabs it properly.

  18. jdn says:

    Hmm, get an invalid zip file error after download. Using WinZip and IE. At client, so perhaps proxy issue?