Saturday, May 18, 2013

ASP.NET Routing: Regex Constraints are inneficient

There are cases where using Regex constraints makes sense and does the job. For example, for action and controller parameters. If you have a constraint like action = "Index|About|Contact", that will prevent the handling, and URL generation, of non-existing actions. The framework only needs a string, from a list of valid values.

Thursday, April 18, 2013

Delegate-based strongly-typed URL generation in ASP.NET MVC

The standard way of generating URLs in ASP.NET MVC involves hard-coding action, controller and parameter names:
string url = Url.Action("Edit", new { id = 5 });
You are probably familiar with the expression tree-based strongly-typed URL generation approach, which is part of the MvcFutures library. It allows you to write code like this:
string url = Url.Action(() => Edit(5));

Friday, March 29, 2013

Attribute-based routing coming to ASP.NET MVC and Web API v5

Attribute-based routing is coming to ASP.NET MVC and Web API, according to the roadmap. They are basing the solution on the popular AttributeRouting project. At the date of writing this post only Web API support is working, you can play with it by installing the nightly packages.

Friday, February 8, 2013

Saturday, January 12, 2013

My life is an anti-pattern

For some reason people often look for THE solution to a particular problem, ignoring the fact that the best solution to any problem depends on its inputs. In other words, if someone asks you something there are two answers that are always correct: I don't know and it depends. These phrases probably won't help you much if you are a business man of a politician, but as programmers we should feel comfortable saying, specially the latter. Because, that IS what we do, right? Take some input, program some logic and return a result.

Thursday, November 1, 2012

MvcPages: ASP.NET MVC without routes and controllers

I like developing with ASP.NET MVC, but sometimes I feel there are too many pieces involved. To develop a single function you have to (in no particular order):
  • Create route (make sure it doesn't break other routes)
  • Create controller/action
  • Create view model
  • Create view
... in addition to writing the model/service that does the actual work. Even though this layering gives you a lot of flexibility and testability, sometimes you don't need it. Do you really need all of the above to develop a simple contact form? Do you ever test your controllers/views? Do you have a lot of actions that just return View()?

Saturday, October 27, 2012

Implementing a contact form plugin for ASP.NET MVC

The purpose of this post is to demonstrate the patterns presented in the Patterns for ASP.NET MVC Plugins series so far.
  1. Routes, Controllers and Configuration
  2. View Models
  3. Demo: Implementing a contact form plugin
I've chosen the contact form scenario because it's a very common requirement most developers are familiar with. Also, the implementation is short and straightforward. The idea is that you focus on the patterns rather than the actual functionality of the plugin. The same patterns can be used to implement more interesting plugins.

Sunday, September 23, 2012

5 reasons why you should use MvcCodeRouting

MvcCodeRouting v1.0 is out, this post highlights the library's most important features and why I believe is a must have for all ASP.NET MVC developers.