Recently, I have been developing quite a big website using ASP.Net MVC Preview 2 framework. Itself it has several nice features but to build a high testable, loosely coupled application we need something more than we get. MvcContrib is a good source of a few nice ideas which can help you in testing, designing and developing your application.
TDD in ASP.MVC is the main reason why I’ve chosen it
ASP.Net with their code behind for views was always a bit too messy for me. For sure there are several ways to use pure ASP.Net with good test coverage but I was looking for something cleaner. Then, ASP.Net MVC appeared on the horizon. (Earlier I was using Castle Monorail Framework which is very similar to ASP.MVC). A clear division between View, Controllers and Model makes it all much easier to test. At least, this framework makes it much easier. However, without proper architecture built on ASP.Net MVC Framework we can still have many issues testing it right. That is why IoC was invented in my opinion, and thanks to MvcContrib you can find there IoC implementations for well known Containers (StructureMap, Windsor, Spring.Net etc.). To be clear, MvcContrib does not provide the IoC container implementation, but it shows how to populate the IoC in ASP.MVC for their Controllers Factory.
MvcContrib offers testing library for HTTPContext mockups
Thanks to Test Helper (I’ve used it recently in my projects) I can test controller and mock HttpContext. Test Helper offers very simple approach to create new controller instances, testing abilities for view generations, routing rules.
Portable areas is an approach to develop one-in-assembly plugins
MvcContrib implements a nice approach for implementing fully separated, loosely coupled plugins. Each Portable area is a separate control with its own assembly. The communication between such a portable area and a host application is made in a messaging way. More about portable areas you can read here. The big advantage of using portable areas is the fact that a developer is aiming at reusability of the component. This means that library is built and can be directly used in other project as well.
FluentHtml is shipping compile time checking to your views
ASP.MVC views are endpoint were developers can make several huge mistakes by coding there some business logic or by writing some magic strings to make view more customizable. With FluentHtml you can do it all but in pure C# code so when you refactor one of your classes it will automatically be caught in your views.
Other nice improvements are also worth mentioning
- Strongly-typed RedirectToAction
Enables you to redirect between controllers using lambda expressions.
- BinaryResult, XmlResult
Allows to return from MVC Controller binary result and xml result.
PostOnly Filter, PreCondition Filter, Rescue Filter, Layout Filter, TempDataToViewData Filter, ModelStateToTempData Filter
In general these filters are meant to help you manage your views when you want to show error, change layout of the site (Master page), pass data to view.
- View Engines
Brail, NDjango, NHaml, NVelocity, SharpTiles, Spark, StringTemplate, XSLT
Thanks to these implementations you can use your favorite approach in defining views.
Hash – allows us to add elements to dictionary using lambda syntax.
MvcContrib is very young but already a pretty nice set of libraries that can speed up your development process and improve quality of your code today.