Wednesday, February 24, 2010

Maintainable MVC Series: View hierarchy

This article is part of the Maintainable MVC Series.


The view system of ASP.NET MVC knows the followings types of views:



  • Master views

  • Page views

  • Partial views


The regular page view contains the specific html and presentation of data for each rendered page. For html shared by multiple pages - like navigation, header and footer - every page has a master page.


Both of these types can include partial views for small parts, that can be reused from multiple views. For example page navigation for display of results covering multiple pages, or widgets. Even if they're not reused it is useful to separate parts of your page view or master view to partial views, to keep the (master) view itself comprehensible and maintainable.


For using partial views in the master view we have a special way to provide them with data (which is sometimes specific to the page requested, like which menu item is active). This is explained in the future part Poor Man's RenderAction.

Tuesday, February 09, 2010

Maintainable MVC Series: Inversion of Control Container - StructureMap

This article is part of the Maintainable MVC Series.



To make your code testable the pattern to use is that of Dependency Injection. DI is nothing more than injecting all dependencies of a class instance through the constructor (or setters if you wish, but less intuitive when reading the code, and doesn't guarantee all dependencies are set). For example if you have a controller that uses a factory and a repository you can both inject them into the constructor as follows:



[csharp]
public class Controller
{
private readonly IFactory factory;
private readonly IRepository repository;

public Controller(IFactory factory, IRepository repository)
{
this.factory = factory;
this.repository = repository;
}
}
[/csharp]

Maintainable MVC Series: Introduction

I'm going to do a series on how I've set up a number of ASP.NET MVC projects for customers with very high-traffic sites and continuously changing functional requirements. In these projects the design evolved to the one that I'm going to describe in detail.


The following subjects will be handled in oncoming blogs: