With the upcoming release of the Microsoft ASP.NET MVC Framework, one might wonder how it compares to the Web Client Software Factory ( WCSF ) and its use of Model-View-Presenter Pattern.
Simon Ince has a nice post on the differences between the ASP.NET MVC Framework and the View-Presenter Pattern in WCSF.
Here are a few similar points that I rather like about the ASP.NET MVC Framework, but it is nice to have both options.
Re-Use of Views
One of the huge differences in my opinion is that a View can be reused across many controllers in the ASP.NET MVC Framework, whereas the View in WCSF is tied to a specific Presenter.
In the WCSF, the Presenter Class is injected into the View via an ObjectBuilder [CreateNew] Attribute and a little code hidden in the Page or UserControl Base Classes:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
WebClientApplication.BuildItemWithCurrentContext(this);
}
The point being that the Presenter Class is referenced in the View and the view only talks to that Presenter.
In the ASP.NET MVC Framework, one specifies the View to be rendered in the Controller Class, allowing one to reuse Views across all controllers. The RenderView() methods on the Controller base class specify the View we want to use, as well as explicitly pass in the specific data that we want the View to use to render its response:
public class CustomersController : Controller
{
public void Customers()
{
List<Customer> customers = CustomerDataSource.GetCustomers();
RenderView("Customers", customers);
}
}
Front Controllers vs. Application Controllers
The Controller used in the ASP.NET MVC Framework is a Front Controller where the Controller used in the WCSF is an Application Controller.
Client requests hit the Front Controller first in the ASP.NET MVC Framework:
- Controller Gets Request
- Interacts with the Model
- Chooses a View
- Passes the Results to the View
The Application Controller in the Web Client Software Factory gets called after the View and Presenter:
- View Gets Request
- Presenter Gets Injected Into View
- View Passes Request to Presenter
- Presenter Passes Request To Model ( could be Application Controller )
- Presenter Passes Results To View
The Front Controller in the ASP.NET MVC Framework is a totally different kind of Controller than the Application Controller in the WCSF.
Conclusion
It is great to have both options: the ASP.NET MVC Framework and the use of the Model-View-Presenter Pattern in the WCSF. I would expect to see wonderful guidance created by the Microsoft Patterns & Practices Team to help implement, understand, and deploy ASP.NET MVC Web Applications.