My favorite Web Application Architecture
This is my first blogpost and I thought I should start writing about the web application architecture i normally choose these days, –if I am allowed by the client to refactor or start from scratch. Hopefully more blogposts will come out of this.
The first thing I do is splitting the Web Application in a html part and a JSON REST API part. Typically the Visual Studio folder structure looks like this:
- WebApplication1.WebSite
- WebApplication1.RestApi
HTML
I use the Razor viewengine in combination with Knockout.js to write the databinding and other than this the HTML is mostly consisting of a bunch of DIVs and script elements with jquery $.get or $.post’s. Normally I am that lucky in projects that I do not have to care about the “colors and stuff”, there is normally another guy taking care of the CSS. My main focus is therefore to get the databinding right and have a nice and clean architecture “downwards”.
REST API
I design the REST API service methods with the view in mind. So instead of having a super-generic method that works for “all web pages” I rather have several specific ones. I want to have as little logic in the client side as possible. I can then design my viewmodel-classes to consist of just the data needed, both translated and formated the way i want.
CQRS style: When working with the REST API I like to split the GET and POSTs as done in CQRS.
- The GET-methods are fetching data from the database through a simple ORM like for example: EF, Dapper, Massive or Simple.Data. If working with a documentdatabase as for example RAVENDB the queries will go directly to its DocumentSession.
- The POST-methods will have the business logic and sometimes be long running processes. A reliable service bus as nServiceBus is therefore to prefer. When working with long running and asynchronous processes special care must be taken when designing the UserInterface (HMTL pages). They can normally not be designed as done when working with request-response-based applications.
Environment:
If the team developers are writing tests and the application above is on GitHub using TeamCity with Continuous Deployment, then my day is perfect!
jQuery validation not working in IE7 and IE8
When you create a new ASP.NET MVC 3 Project in Visual studio, your script folder will by default contain among others:
jquery-1.5.1.min.js
jquery.validate.min.js (which is version 1.8.0)
One of the first things you might want to do is update the jquery version to the latest version, which today is version 1.7.1
After doing this, your client side validation will stop working in Internet Explorer 7 and Internet Explorer 8.
This is because the jquery.validate version is not compatible with jquery versions > 1.6. The solutions is simple, you need to update your version of jquery.validate as well. You can find the current version 1.9 from Microsoft’s CDN or the latest version from GitHub here:
Microsoft Ajax CDN: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js
GitHub Jquery Validation: https://github.com/jzaefferer/jquery-validation/downloads
Remember that you can always find the latest javascript library in Microsofts CDN, see the complete list of available libraries here: http://www.asp.net/ajaxlibrary/cdn.ashx

