Silent lately

Published on Apr 14, 2009

I have been silent lately because I have been working on a project based on ASP.NET MVC. The idea is to have the bare minimum to create highly configurable sites.

The main obstacles I saw with the framework “out of the box” is how to create composite views.

This project is driven by a real need in the company I’m working right now. Let’s explore together the design and development process that we follow. Please note that I’m not saying the all the decisions taken so far are final or even the right decisions. I have changed my mind several times and there are still some things that I know I need to change to make it better.

Here are the basic requirements:

  1. Separation of concerns, specially separation between presentation and business logic.
  2. Views (web pages) should be written in html and they should validate before compiling.
  3. Layouts should be pluggable, supporting different sites with one installation.
  4. Content on the pages should be modular, think widgets.
  5. Different sites should be able to use different combination of widgets in the same url.

1. Separation of concerns

The code needs to be easy to maintain and extend. Separation of concerns and the rest of the S.O.L.I.D. principles helps to achieve this.

The first way to achieve this is to use some of the well know presentation patterns. I’m partial to MVC but I decide to take another look at MVP. I have to admit that both of them were suitable for this project, but at the end of the day, I choose MVC just because I like it better and I have more experience with other frameworks that implement it (Struts, CakePHP, RoR, Symphony).

Why ASP.NET MVC?

We choose .Net as our development technology, that left me with a few choices:
MonoRails, ASP.NET MVC, FubuMVC, Sharp Architecture, ProMeshMVC and a few others.

I decided to go with ASP.NET MVC (note that Sharp Architecture is based on it and is more of a complete architecture). I was very tempted with ProMesh. I use it in a few pet projects and I really like it, but the community that is building behind ASP.NET MVC is a very appealing feature.

2. Views should be valid html.

Ok, I know that this is controversial. I consider myself a pragmatism. I’m a proponent of semantic html and Css based layouts instead of tables.

At the same time I’m not totally against using tables in some situations. But I despise written invalid html. I’m not talking about XHTML strict (although there is not a big deal to do so), I’m just talking about valid HTML 4.0.

That is a problem with most template systems out there. They all include code somehow inside the html, making the html invalid. One of the works around is to write the html, validate it and them moved into the template system of your choice, with the risk of breaking it.

The solution was to create a simple html based view engine. I considered using Sparks, that is the closest thing I found to what I was looking for, but It has stuff like this:

Sparks is awesome, and I will use it in my next project for another site that I’m doing but It won’t fit the bill for this one.

3. Support different sites with one installation.

This is a content management system, so different domains point to the same install but they should support different layouts for the same url:

ex: www.domain.com/movies/list should use the same code but look different to www.anotherdomain.com/movies/list

4 and 5. Widgets on pages.

The idea is that a layout defines different areas and each can contain different widgets. Again each site should be able to define the widgets per area per layout. The code for the widgets should be independent for the controllers and the actions mapped to a url.

Enough analysis, in a next post some of the code.