BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Rethinking Models in MVC

Rethinking Models in MVC

Bookmarks

Jon Galloway is researching dynamic ASP.NET MVC 3 models using Mono’s Compiler as a Service. Meanwhile Karsten Januszewski is looking into deserialized JSON in lieu of statically typed models.

Dynamic Models using Mono’s Compiler as a Service

Since we are still two versions away from having compiler-as-a-service support from Microsoft, Jon Galloway’s research started with the recently updated Mono Compiler Service. Mono’s compiler is currently under active development as they lay the foundation for adopting C# 5’s asynchronous language constructs.

The fundamental class here is Mono.CSharp.Evaluator. Calling the Run method on this class will compile whatever string has been passed in. The Evaluate method, which also accepts a string, will process and return whatever expression is given to it. In this sense it is very much like the experience you would get from the Dynamic Language Runtime or the venerable VBScript hosting APIs.

JsonObjects as Models

Karsten Januszewski’s research has taken a decidedly different tact. He starts with JSON-formatted strings that were exposed from the service tier using WCF JSON classes. These are parsed into a JsonObject which acts as the model. The downside here is that there is no place to hang business logic; the model is pure data.

While working on this Karsten ran into an unfortunately common problem for MVC users and an elegant solution. Simply put, the anonymous types that LINQ normally generates are incompatible with the RuntimeBinder used by MVC. This can be generalized to “anonymous types are incompatible with dynamic types”. Fortunately a solution is provided. Simple create new JsonObject’s instead of anonymous types in the LINQ expression.

Rate this Article

Adoption
Style

BT