stevehodgkiss/restful-routing — Issue #43: Strongly typed Additional action registration
Author: SlyNet
Created: 2011-12-20 08:12:49+00:00
State: open

I wanted to discuss some additions to routes registration API. In current version I can write an extension method like this:

```C#
public static class RoutesExtensions
{
public static void Member(this IResourcesMapper mapper, Expression> member, HttpVerbs verb)
where TController : Controller
{
var methodCall = member.Body as MethodCallExpression;
if (methodCall == null)
throw new ArgumentException("member value should be a call to controller action method", "member");

string methodName = methodCall.Method.Name;

switch (verb)
{
case HttpVerbs.Get:
mapper.Member(x => x.Get(methodName));
break;
case HttpVerbs.Put:
mapper.Member(x => x.Put(methodName));
break;
case HttpVerbs.Post:
mapper.Member(x => x.Post(methodName));
break;
case HttpVerbs.Delete:
mapper.Member(x => x.Delete(methodName));
break;
case HttpVerbs.Head:
mapper.Member(x => x.Head(methodName));
break;
default:
throw new NotSupportedException("Provided http verb is not supported");
}
}
}
```

And it will allow to change registration of "Test" in sample site from

```C#
// old version
blogs.Member(x => x.Get("test"));
// new version:
blogs.Member(x => x.Test(0, null), HttpVerbs.Get);
```
Currently I don't like here two things:
1. With lambda expression we need to pass parameters in method
2. Switch statement in the method (it can be removed easily if move this extension method to core assembly and make Route method of AdditionalAction class internal)

But we removed a magic string - method name.
What do you think about it?