Gray's Matter
Justice Gray - North America's favorite metrosexual software consultant

I Wish These People Updated More Than Once a Year


Don't worry, I'm just getting this out of the way pre-emptively

Scott Hanselman's fourth screencast *confirms* that the interfaces and abstractions made as part of the MVC (HttpContextBase, IHttpRequest, IHttpResponse, etc.) will not be put into the existing Webforms model.  That means that once MVC is released, the old HttpContext object in WebForms will *not* inherit from HttpContextBase, nor will the WebForms versions of HttpRequest and HttpResponse objects implement the interfaces.  I don't believe anyone was sure of this happening anyway, but now it is definite.  From about 22 min into the final of the four screencasts:

"There are certain things we would have wanted to have done, for example we would have loved to have pushed out our [HttpContextBase] and our testable interfaces deep down into System.Web, so that other ASP.NET developers could get that functionality as well.  But that would have involved massive changes to the already well-tested codebase of ASP.NET WebForms.  So there are some things that history will not allow us to do, or at least, is going to slow us down."


So if you want to have some easy abstractions around these objects with the good old WebForms model to ease your testing and TDD pains, you have many, many choices:
1) Write wrappers for pretty much *everything* yourself.
2) Forget about testing stuff like that
3) Wire up your own MVP pattern for it
4) I lied, there's really only those choices

Now, once again, like NMock, this doesn't matter all that much to me - I've been moving away from the WebForms model anyway and now Microsoft has made the decision between the two models academic.  All of the cool extensions and abstractions to give ASP.NET web applications better testability are only happening in the Microsoft MVC. Not only that, but the screencast is also implying through the "we would have loved to do this, but we can't" message that what is being done in the MVC is a recognizably better way of doing things than what is happening in the Webforms model.  However, due to historical reasons WebForms is stuck with that model while everything else evolves.  That's right, my friends, WebForms will be the new legacy system! 

To me, this is *huge*.  In fact, for any of you that have been having problems pitching Microsoft MVC in the past, this is even bigger news for you.  I have insanely good looks and absolutely ridiculously awesome hair to rely on, so it really doesn't matter what I say; people agree with me naturally.  Some of you out there might have to rely on things like *facts* to convince *your* stakeholders to use the MVC.  And now you've got your facts - if you are looking to have a unit-testable web application (and trust me, I've got a *boatload* of metrics to indicate that is preferable, if that's really your bag) WebForms cannot be that choice for you.  And yes, for those of you about to tell me all about the glory of Monorail, I know!  But of the Microsoft MVC or Monorail, which one do *you* think is going to be easier to pitch to "BigCo Inc."?

At my presentation in DevTeach (this again!  Really, I should post about it already) I implied -jokingly - that MVC was your *only* choice.  Now this time it's Microsoft implying it, but I don't think they are kidding!

Do you remember the whole religious war several years back about VB vs. C#, and how people would fight for ages about whether one language was better than the other, or whether you were even a better developer for choosing one over the other?  Those were crazy times, thank goodness that got worked out - oh wait, no it didn't.   Well, guess what - those days are here again, but worse.

And you thought *NMock* was in trouble?

[update: the previous three parts in this series can be found by clicking below:
MVC Preview 1 to Preview 2 Part A
MVC Preview 1 to Preview 2 Part B
MVC Bombshell #1]





Thursday, March 06, 2008 #

3/7/2008 9:33:15 AM (Mountain Standard Time, UTC-07:00)
Justice! Are you trying to frighten Mort!?!?! Haven't you seen MS repeated denials that MVC is ABSOLUTELY NOT meant to replace webforms, and is just "an option?"

I guess this approach is pretty good from an MS perspective. Claim you're still supporting WebForms so that you don't have to deal with angry customers, or admit past mistakes... Meanwhile dump all the new stuff into MVC, thereby making WebForms de facto legacy.
3/7/2008 10:07:22 AM (Mountain Standard Time, UTC-07:00)
Justice, I think we can totally agree that the invention of the MVC pattern and framework by Microsoft will be a huge boon on the developer landscape.

OH C'MON NOW, laugh! It's a joke!

D
3/7/2008 9:36:21 PM (Mountain Standard Time, UTC-07:00)
I think that the important point was "for now." There's nothing that says MS can't add these abstractions in later, and I think the very fact that System.Web.Abstractions is NOT System.Web.Mvc.Abstractions should give you some comfort that we know what the *goal* is. ;)
3/7/2008 10:00:04 PM (Mountain Standard Time, UTC-07:00)
Hey, I understand that but really, is there some point in time where this would actually happen? I know it's a lofty goal but if "history prevents us" won't it prevent you 6-9 months from now as well?
3/7/2008 11:14:40 PM (Mountain Standard Time, UTC-07:00)
I honestly don't know if it'll happen, but I know it's possible.
3/7/2008 11:25:18 PM (Mountain Standard Time, UTC-07:00)
Well, I will say (devoid of sarcasm) your optimism is inspiring! To be honest, I would love for that to happen because I think anything that helps knock down barriers to testing is a very good thing. I'm exhuasted enough from the old VB vs. C# stuff that I don't want WebForms to become a 2nd class citizen.

3/8/2008 10:39:59 PM (Mountain Standard Time, UTC-06:00)
Well, notwithstanding the new interface-based HTTP-Object-s in MVC, you still *had* testability with webform development.

The problem was that everyone just threw 5 views worth of business logic and presentation into *one* webform. Instead of breaking up the functionality into different views, you'd have 5 data lists for the different data views, all of which were generated by different button click events that would have to be handled in the code behind which also included the sql call to get the data...all while a convenient "If not page.ispostback" in the page_Load event ensured that initial data loading didn't happen.

So you had webform-based applications written *without* testing in mind. This wasn't an issue with webforms, its an issue with Microsoft focussing on productivity gains with ASP.NET and not proper coding standards and ability to use testing tools and frameworks.

Actually no, its not Microsoft's fault...its the developer community in general evolving to a point where testing is a foremost concern in the planning stages. The ability was always there, but nobody realized it or took advantage of it.

If anyone tries to bring up a "Webform vs MVC" debate they'll get an earful about how there IS no debate, at least from a testing perspective: you get extra bells and whistles with MVC, but if you're putting logic trees into your page_load you need to STFU and let the big boys hammer this one out. (I'm not saying that to *you*, i'm just saying that should be what we say to *them*...but that sounds elitist...ok, maybe a nicer way...wtf, why am I rambling on your blog?)

D
4/3/2008 9:26:00 AM (Mountain Daylight Time, UTC-06:00)
You just made it to the front of DotNetKicks...coolness!
4/3/2008 3:39:15 PM (Mountain Daylight Time, UTC-06:00)
You could completely submit to the mocking gods and require public ABCs, but then there's TypeMock
5/25/2008 10:07:36 AM (Mountain Daylight Time, UTC-06:00)
MVC is not that hard to implement with the current asp.net model. You CAN have ViewState and MVC as well, and it's really not that difficult. ViewState really is a good thing, and if coded properly, it shouldn't get very big. Controls should be bound in your Page_Init method and within control event handlers, and NOT within your Page_Load handler. Why? Because view state is tracked / restored AFTER Page_Init. This means anything you change about your controls after Page_Init will be thrown into viewstate including all bound data. UserControls also needed to be added to the control tree in Page_Init so that they can participate in the ViewState tracking.
Using MVC in WebForms is done using "multiple" controllers (one for each view), and User Controls as views. The user controls should be placed in your App_Code directory (even though they say you shouldn't), and loaded with the version of LoadControl that accepts a class type, not a file path. the user controls should only contain code that is involved in rendering itself based on a data context provided by the controller.
The asp.net page instantiates the controllers and "loads" the views (using LoadControl), and passes the view instantance to the controller, and thereafter adding the view to the "controls" collection of a placeholder control in Page_Init.
Since the controller has a strongly typed reference to the view, it can subscribe to it's events and handle them.
As far as testability is concerned, I haven't really looked it to that because as of right now, I'm not doing TDD, however, I really do think it's possible (perhaps using the framework itself as the test container).
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):