Karl Seguin

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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: http://codebetter.com/blogs/karlseguin/archive/2008/06/24/foundations-of-programming-ebook.aspx)

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 Stick out tongue. There's extensive use of Lambdas, so if you have a hard time reading them, I hope my excessive examples will help illuminate them.


Posted Fri, Jul 18 2008 9:34 AM by karl
Filed under:

[Advertisement]

Comments

Karl Seguin wrote Foundations of Programming Ebook
on Fri, Jul 18 2008 9:48 AM

I'm excited to finally release the official, and completely free, Foundations of Programming EBook

DotNetKicks.com wrote Foundations of Programming - Learning Application
on Fri, Jul 18 2008 10:39 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

jdn wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 11:06 AM

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

jdn wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 11:17 AM

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

karl wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 11:35 AM

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

www.thecodewiki.com/CodeBetter.Awards.zip

(thanks for letting me know about the problem jdn)

DaRage wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 12:05 PM

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

karl wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 1:06 PM

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?

Adriaan wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 4:14 PM

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?

karl wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 4:29 PM

Adriaan:

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.

Adriaan wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 4:59 PM

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?

karl wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 6:02 PM

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 (martinfowler.com/.../tableDataGateway.html). You can use it with an O/R mapper together.

jdn wrote re: Foundations of Programming - Learning Application
on Fri, Jul 18 2008 9:31 PM

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.

ASP.NET MVC Archived Blog Posts, Page 1 wrote ASP.NET MVC Archived Blog Posts, Page 1
on Fri, Jul 18 2008 10:48 PM

Pingback from  ASP.NET MVC Archived Blog Posts, Page 1

Dew Drop - July 19, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - July 19, 2008 | Alvin Ashcraft's Morning Dew
on Sat, Jul 19 2008 9:26 AM

Pingback from  Dew Drop - July 19, 2008 | Alvin Ashcraft's Morning Dew

DaRage wrote re: Foundations of Programming - Learning Application
on Sat, Jul 19 2008 9:26 AM

It works now. Thanks karl.

Reflective Perspective - Chris Alcock » The Morning Brew #140 wrote Reflective Perspective - Chris Alcock » The Morning Brew #140
on Mon, Jul 21 2008 3:17 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #140

Weekly Links #10 | GrantPalin.com wrote Weekly Links #10 | GrantPalin.com
on Mon, Jul 21 2008 12:16 PM

Pingback from  Weekly Links #10 | GrantPalin.com

Foundations of Programming « Build and Deliver wrote Foundations of Programming « Build and Deliver
on Tue, Jul 22 2008 7:55 AM

Pingback from  Foundations of Programming « Build and Deliver

Steve wrote re: Foundations of Programming - Learning Application
on Fri, Jul 25 2008 7:28 AM

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.

karl wrote re: Foundations of Programming - Learning Application
on Fri, Jul 25 2008 8:31 AM

@Steve:

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

Rik wrote re: Foundations of Programming - Learning Application
on Fri, Aug 8 2008 4:39 PM

Hi,

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).

Regards,

Rik

Bob Baker wrote re: Foundations of Programming - Learning Application
on Tue, Nov 18 2008 11:58 PM

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.

bbaker@microapplications.com

Giorgi wrote re: Foundations of Programming - Learning Application
on Tue, Dec 16 2008 8:43 AM

Hello,

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 asp.net demo (not asp.net mvc version) too? I believe many users (including me) would find it useful

Thank you once again.

Andy wrote re: Foundations of Programming - Learning Application
on Thu, Jun 11 2009 7:47 AM

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.