Mercurial SCM (Hg) is a Distributed Version Control System (DVSC). More importantly, your code doesn’t know or care how it is being versioned. In other words, None of your VS solution or project files will be modified with a pointer to source control, and no *.scc files will be added in your code.
Lots of programmers I talk to are managing software assets written in ASP.NET. These applications have been in production for years, and they work. The problem that is pervasive among all of them is that the Page_Load method is much too large. Model-View-Presenter is fatally flawed as a pattern because the view obtains control before the presenter does. This wrong ordering is an unrecoverable error in the workability of the pattern. I have spent a number of years attempting to implement the MVP pattern well before I came to this conclusion.
This post contains a short example that inserts a controller in the request pipeline before the Web Form. This allows large and bloated Page_Load methods to offload a bit of logic to a controller that executes in front of the Web Form. Interestingly enough, this same technique allows an ASP.NET MVC page to leverage post-backs and server side controls.
Here is the solution view:
Default.aspx.controller.cs is the controller that executes ahead of Default.aspx. The Visual Studio tooling doesn’t know to nest this file like I would like it.
Here is the page run the first time:
And here is the page after 3 clicks on the button that is an <asp:Button/>
Our page looks like the following:
<%@ Page Language="C#" AutoEventWireup="true"
Inherits="MvcApplication1.Controllers.Default" %><%@ Import Namespace="MvcApplication1"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title></title></head><body><formid="form1"runat="server"><div><%var cust = (Customer) ViewData["model"]; %><h1>Web Form with front controller</h1>
Customer #: <%=cust.Id %><br/>
Name: <%=cust.Name %><br/>
Is Preferred: <%=cust.IsPreferred %><asp:ButtonText="Do a postback"runat="server"ID="btn"onclick="btn_Click"/></div></form></body></html>
Notice that I overrode the Execute method. In this case, there is no need for the concept of an action. We merely have an object that executes before the Web Form. Then the controller builds the Web Form and asks it to process the request.
Half of this method could easily be factored into another class, but it works very simply. I did not have to jump through any hoops. I hammered out this code in about 10 minutes.
If your Page_Load methods are getting too long, consider putting a front controller in front of the page.
In the Nov/Dec 2009 issue of CODE Magazine, I submitted an article entitle “ASP.NET MVC 2 in Action”. You can read the full article online here. I wanted to write this short post to let the public know where to get the source code used for the article. You can download the code here.
Back in 2005, I purchased an mVox 100 (mv100). This device worked great on Windows XP, and I used it in various VOIP application. Really great USB speakerphone. It’s tiny, also, and I kept it tucked in my back for the last 5 years.
When I upgraded my computer to Windows Vista, I was rather disappointed that this useful little device no longer worked.
I could not find any Vista drivers. From what I gleaned from forums, it relied on usbaudio.sys, which was overhauled in Windows Vista. Even though I couldn’t use the device, it stayed in my computer bag for 2 years! I switched computer bags today and uncovered this little speakerphone. I decided to give it a shot on my Windows 7 computer. Lo and behold, it worked! No driver install. I plugged it in, it detected it, and registered both the built-in microphone and sound card/speaker. I happened to have Skype open, and Skype immediately registered the device as the microphone and speaker. Bottom line: I am impressed by Windows 7 once again!
According to NetMarketShare, Internet Explorer still has, what is considered in politics, a 62.18% complete landslide domination of the other browsers.
So we can read: 62% IE, and 38% “not IE”. But that doesn’t work in practice because the other 38% is fragmented among at least 4 other major players (major being defined as more than 1% market share, or about 17,300,000 installations). Think about it. Opera has over 41 MILLION users. So that 2.38% is still not anything to sneeze at. . . unless you are serving the 1,075,714,000 IE users. Wow. over 1 billion Internet Explorer users. (Internet stats from “Internet World Stats”)
At Headspring, most of the current market wants a mix of web, windows, and mobile business applications with a heavy, heavy lean towards web applications. As a Microsoft shop, ASP.NET is dominating the line-of-business space for us. We have to decide which browsers to support (which really means which browsers to heavily test). Yes, the client might have some browser preferences, but most of our clients trust us to do the right thing for them. So what do we do, and what browser do “I” run? See above (I run them all).
First, we have to look at the base of users and what browser they are typically running. A really popular combination is IE 7 and Firefox 2. Yep. Version numbers. We have successfully deprecated IE 6 support down to the functional level (must work in IE 6, but visual discrepancies won’t be fixed) because clients have either migrated or they plan to migrate within a year, and we present the cost/benefit of the alternatives. Any clients needing Chrome support? Nope. none. not even a mention. Now, in our experience, if a web application works properly in IE 7 AND Firefox 2, it is highly likely to be just fine in the other browsers.
Now for me. Yes, I run all the browsers, but I have chosen one for my day-to-day browsing needs. That browser is Google Chrome 4. Not Chrome 3 or 2. But 4. And it’s only today. Why? Because I think Microsoft is going to wake up and deliver a really killer Internet Explorer that will push it’s market share back to 90% in the coming years.
Let me back up: for running software applications, it is critical to use the browser that the client will be using (and if it requires a different version of IE, then just run it from Windows 7 XP Mode). If your client is predominantly Firefox (like some timid IT departments now), then you must test your app predominantly in Firefox. Same for IE. Ignoring the dominant browser at your client is a really good recipe for obvious bugs to slip through.
Now, why Google Chrome 4? Because of the architecture of the browser coupled with new support for extensions. Each tab runs in its own process. This is critical because it delegate memory isolation and threading to the operation system instead of trying to manage them all within a single browser process. Next is extensions. First, and my favorite, is the IE Tab extension, ported from IE Tab as a Firefox extension. It runs the page in the IE rendering engine but inside a Chrome tab (which is isolated to one process). Note that this cannot fully replace actually TESTING with IE proper for your clients.
Below is an image of two Chrome tabs. The top is regular, and the bottom is with IE Tab.
My next favorite extension is just named “Keyboard Navigation”. It’s just like the really great Numbered Links Firefox extension that makes it possible to really browse the web without the mouse. You press the comma(,) hotkey to pop up the shortcuts, then choose your link. The enter key directs your browser to follow the link. All while keeping your fingers on the home row.
I don’t use IE and Firefox anymore for my normal browsing for one single reason: The process architecture. Having all the tabs in a single process produces a slow browsing experience (when contrasted with the alternative). Does Chrome slurp up more memory? Absolutely. Here is a screen shot of all the processes.
A quick glance produces over 500MB or RAM used just for the browser. If I was worried about RAM (and willing to spend my time waiting in order to save RAM) I would probably make another decision. But, when all my guys are equipped with 8GB of RAM in the company computers, it’s just not a constraint to worry about.
I’m not an Internet Explorer MVP, so I don’t get early access to IE information and roadmap plans, but I do expect a big breakthrough on that front to be announced in 2010. I think the sleeping browser giant is about to wake up.
Jimmy Bogard just made the announcement that AutoMapper is now 1.0. Babies grow up so fast. Jimmy has cultivated this project since it’s infancy, although I think almost everyone from Headspring has at least one commit (I think I had a total of 3 commits, perhaps).
For those who don’t know, AutoMapper is an object-to-object mapper, and you can read more about it on the CodePlex documentation wiki as well as inside the book, ASP.NET MVC in Action. AutoMapper is very, very useful when mapping from persistent objects to view model objects, but that is just one of the uses.