Coding Smarter
Official Blog of Al Katawazi

Error Driven Development with MVC Framework

June 19, 2009 09:33 by Al Katawazi

Before the flame war starts up I want to say I believe in test driven development BUT you really don't need unit testing for every single class that you create. I'm sorry but the AboutUs controller method seriously does not need a unit test. Those of you who are in shops where unit testing is forced on you then you realize how time consuming it can be to create good unit tests. Especially if your lazy and wait till the end of the week to make them. So for those of you who want to make reasonably stable applications and not have to create all this unit testing classes then you can try this:

public class ErrorLoggingAttribute : ActionFilterAttribute
{
 public override void OnActionExecuted(ActionExecutedContext filterContext)
 {
   if (filterContext.Exception != null)
   {
       CustomErrorHandlingClass.ReportError(filterContext.Exception);
   }
  }
}

So you'd place this code in one of your controllers and this would create a method attribute that you can use throughout your MVC Application. What that would like like is something like this:

[ErrorLogging]
public ActionResult Index()
{
   return View();
}

Its that easy, and when an error happens your CustomErrorHandling Class can notify you in some way that there is a problem such as an email. I can't tell you how many times this has found deep errors in my system (stuff the unit testing would of never found). Now I am not saying get rid of unit testing, but you may just want to reserve it for mission critical stuff like making sure your ShoppingCart class is adding properly :D.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

MVC Blogger Project

May 12, 2008 16:19 by Al Katawazi

After much searching on the web for a decent blogging engine that is built off of dotnet, I was left empty handed. The best I could do was BlogEngine.net for the time being. I am going to be starting up a project to develop a new blogger that will use the MVC framework. The advantages of using MVC is that it interprets URLs and displays HTML views based on the URL.

Ex: www.codingsmarter.com\article\MVCBlogging is all that is needed with MVC, that same page using traditional asp.net pages would be something along the lines of www.codingsmarter.com\default.aspx?article=MVCBlogger . The reason this sucks is because google will drop off anything after the ? for search engine purposes, and you are left with a diminished ranking in the search engine.

More to follow later on this project.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , ,
Categories: MVC
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed