Saturday, March 17, 2012

Web Controllers in the "modern" age

Something that doesn't sit quite right with me about "RESTful" controller libraries is their desire to want to handle all of the requests for a resource. Take for example ASP.Net MVC, whose controller classes are strongly influenced Rails.
Why is it that we think it's OK for a class to have 7 methods on it? What happened to having a class per action? What happened to separating Commands from Queries? WTF is going on!

Update: Here is a example app from Microsoft's Patterns and Practices group; it encourages using commands to back controller actions:
var vehicles = Using<GetVehicleListForUser>().Execute(CurrentUserId);
I think this incredibly promising and an excellent approach to decoupling your business logic from the HTTP layer of your application. It reminds me very much of WebWork a.k.a. Struts2, which is my favorite Java web library because it allows me, the developer, to worry about the domain and not wasting cycles on having to write boiler plate web-centric code. If you have not seen them yet, Uncle Bob Martin and Cory Haines describe similar design techniques in conference presentations.
I think that Microsoft should take ASP.Net MVC one step further and simply make this design part of the library and just get rid of an entire layer of non-productive work for us.  

No comments: