This is big. I arranged a special meeting (with the help of Karl) with Scott Guthrie today on the last day of the MVP Summit. I brought along fellow CodeBetter bloggers Darrell Norton, Scott Bellware and Jeremy Miller. Scott laid out a concept for how to make ASP.Net better support MVC much like Rails and MonoRail try to conform to this model.
If you aren’t familiar with MVC frameworks, the most important thing to know is that the Controller is king. The view only spins up and renders if the Controller decides it is the right thing to do.
With Scott’s prototype, there is a new handler factory that infers from the URL which controller to instantiate and load. The controller then decides what to do with the request. The controller can load a view (.aspx file) and let it render. The view can access properties of the Controller. The ASP.NET lifecycle and control model and still be used in the view, or you can let the Controller render a view of customized templates. Either way, the Controller is in control.
This model allows the Controller to be unit tested easily since contact with the HttpContext, Request, Response, etc can be easily mocked with this model.
The codebehind and markup is the view (what I’ve been saying all along), and it is completely subordinate to the Controller. The view isn’t even created until the Controller decides it is time.
With the model, the need for Model-View-Presenter goes away for web apps. I used M-V-P in the passed to get around the control model and get control to a testable class. With this new MVC framework, the Controller goes first and runs the show for the whole request.
A url might look like http://localhost/myApp/ShoppingCart.mvc/CheckOut where ShoppingCart is the Controller class and “CheckOut” is a method like:
[Action]
public void CheckOut(){
//do something
}
For post-backs, the control model still works and the view can delegate to the controller, but I have asked that this be looked at hard with the goal of putting the controller in charge of post-backs as well when needed. Scott is very open to feedback, and he plans to involve community experts in the planning of this new framework.
It might be hard to imagine this new framework from just this blog post, but trust me. This is very cool, and ScottGu is headed in the right direction. I’ll vouch for that. We’re going to end up with a new ASP.NET paradigm that so much easier to work with and, most importantly, easier to test!
Great concept Scott. I love what you are doing.
UPDATE: More info http://codebetter.com/blogs/jeffrey.palermo/archive/2007/10/05/altnetconf-scott-guthrie-announces-asp-net-mvc-framework-at-alt-net-conf.aspx