One of the things that happens people have asked for over the years with ASP. NET is built-in support for developing Web applications using
Model-View-controller (MVC) based architecture.
Last weekend at the alt. net conference in Austin I gave the first public demonstration of a new ASP. net MVC framework that my team has been working on. you can watch a video of my presentation about it on Scott hanselman's blog here.
We'll be releasing a Public Preview of this ASP. net MVC framework a little later this year. we'll then ship it as a fully supported ASP. NET feature in the first half of next year.
What is a model View Controller (MVC) framework?
MVC is a framework methodology that divides an application's implementation into three component roles: models, views, and controllers.
- "Models" in a MVC Based application are the components of the application that are responsible for maintaining state. often this state is persisted inside a database (for example: we might have a product class that is used to represent order data from the products table inside SQL ).
- "Views" in a MVC Based application are the components responsible for displaying the application's user interface. typically this UI is created off of the model data (for example: We might create an product "edit" view that surfaces textboxes, dropdowns and checkboxes based on the current state of a product object ).
- "Controllers" in a MVC Based application areComponents responsible for handling End User Interaction,Manipulating the model, and ultimately choosing a view to render to display UI.In a MVC application the view is only about displaying information-it is the Controller that handles and responds to user input and interaction.
One of the benefits of using a MVC methodology is that it helps enforce a clean separation of concerns between the models, views and controllers within an application. maintaining a clean separation of concerns makes the testing of applications much easier, since the contract between different application components are more clearly defined and articulated.
The MVC pattern can also help enableRed/greenTest driven development(TDD)-Where you implementAutomatic Unit Tests, Which define and verify the requirements of new code, firstBeforeYou actually write the code itself.
A few quick details about the ASP. net mvc Framework
I'll be doing some in-depth tutorial posts about the new ASP. net MVC framework in a few weeks once the bits are available for download (in the meantime the best way to learn more is to watch the video of my alt.net presentation ).
A few quick details to share in the meantime about the ASP. net mvc framework:
- it enables clean separation of concerns, testability, and TDD by default . all core contracts within the MVC Framework are interface based and easily mockable (it supports des interface based ihttprequest/ihttpresponse intrinsics ). you can unit test the application without having to run the controllers within an ASP. net Process (making unit testing fast ). you can use any unit testing framework you want to-do this testing (including nunit, mbunit, MS test, etc ).
- it is highly extensible and pluggable. everything in the MVC framework is designed so that it can be easily replaced/customized (for example: you can optionally plug-in your own View engine, routing policy, parameter serialization, etc ). it also supports using existing dependency injection and IOC container models ( Windsor, spring. net, nhib.pdf , etc ).
- it implements des a very powerful URL Mapping component that enables you to build applications with clean URLs . URLs do not need to have extensions within them, and are designed to easily support Seo and rest-friendly naming patterns. for example, I cocould easily map the /products/edit/4 URL to the "edit" action of the productscontroller class in my project above, or map the /blogs/scottgu/10-10-2007/sometopic/ URL to a "displaypost" action of a blogenginecontroller class.
- the MVC Framework supports using the existing ASP. net. aspx ,. ascx, and. master markup files as "view templates" (Meaning you can easily use existing ASP. NET features like nested master pages, <%=%> snippets, declarative server controls, templates, data-binding, localization , etc ). it does not , however, use the existing post-back model for interactions back to the server. instead, you'll route all end-user interactions to a controller class instead -which helps ensure clean separation of concerns and testability ( it also means no viewstate or page lifecycle with MVC Based views ).
- The ASP. net mvc FrameworkFully supports existing ASP. NET featuresLike forms/Windows authentication, URL Authorization, membership/roles, output and data caching, session/profile State management, health monitoring, Configuration System, the provider architecture, etc.
Summary
If you are looking to build your web applications using a MVC approach, I think you'll find this new ASP. net MVC framework option very clean and easy to use. it will enable you to easily maintain separation of concerns in your applications, as well as facilitate clean testing and TDD.
I'll post more tutorials in the weeks ahead on how the new MVC features work, as well as how you can take advantage of them.
Hope this helps,
Scott