ASP.NET MVC vs. Exyus
i sat down for a bit last night and started reviewing the ASP.NET MVC shopping demo with an eye to implement the same thing using my Exyus engine. i thought it might take a bit of doing. i was wrong [grin]. within a few minutes i'd modeled two resources (Categories and Products) and compiled a pair of Exyus classes that 'just worked.'
even better? when i compiled the two classes, i got read/write functionality 'out of the box' for free. since Exyus classes are set to handle the full range of HTTP Methods (GET POST PUT DELETE HEAD
), it was trivial to be able to allow authorized users the ability to fully manage resources. not bad.
here's all the code:
using System; using System.Collections.Generic; using System.Text; using Exyus.Web; namespace Exyus.ShoppingExample { // example xmlfile handler for a product resource [UriPattern(@"/products/(?<pid>[^/]*)(?<tail>\.xcs)(?:[\?](?<args>[^#]*))?(?:#(?<frag>.*))?")] public class productsResource : XmlFileHandler { public productsResource() { this.ContentType = "text/xml"; this.AllowPost = false; this.AllowCreateOnPut = true; this.LocationUri = "/products/"; this.DocumentsFolder = "~/documents/products/"; this.StorageFolder = "~/storage/products/"; this.XHtmlNodes = new string[] { "//description" }; this.LocalMaxAge = 600; this.ImmediateCacheUriTemplates = new string[] { "/products/", "/products/{pid}" }; } } // example xmlfile handler for a product catetgory resource [UriPattern(@"/products/categories/(?<cid>[^/]*)(?<tail>\.xcs)(?:[\?](?<args>[^#]*))?(?:#(?<frag>.*))?")] public class productsCategoriesResource : XmlFileHandler { public productsCategoriesResource() { this.ContentType = "text/xml"; this.AllowPost = false; this.AllowCreateOnPut = true; this.LocationUri = "/products/categories/"; this.DocumentsFolder = "~/documents/products/categories/"; this.StorageFolder = "~/storage/products/categories/"; this.XHtmlNodes = new string[] { "//description" }; this.LocalMaxAge = 600; this.ImmediateCacheUriTemplates = new string[] { "/products/categories/", "/products/categories/{cid}" }; } } }
of course, this is the controller. the model is the file system (since i choose to use the XmlFileHandler, not the XmlSqlHandler). the views are (for now) just a bit of XSLT to transform the item collection into a hyperlink list. i have no XSLT for the item view - i just echo back the existing XML. i know the ASP.NET MVC presents slick XHTML views. i choose to leave that for the next step - a set of clean XHTML templates to go along with the pain 'data' views. see, that's another good thing about Exyus. i can publish a clean, fully functional XML API set *and* some customized XHTML views against the data.
more to come...