Created
October 27, 2011 20:02
-
-
Save jeremiahredekop/1320697 to your computer and use it in GitHub Desktop.
weakly typed MapServiceRoute method for webapi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using Microsoft.ApplicationServer.Http; | |
using Microsoft.ApplicationServer.Http.Activation; | |
namespace System.Web.Routing | |
{ | |
public static class CustomRouteCollectionExtensions | |
{ | |
public static void MapServiceRoute(this RouteCollection routes, Type serviceType, string routePrefix, HttpConfiguration configuration = null, object constraints = null, bool useMethodPrefixForHttpMethod = true) | |
{ | |
if (routes == null) | |
throw new ArgumentNullException("routes"); | |
if (configuration == null) | |
configuration = routes.GetDefaultHttpConfiguration(); | |
var serviceHostFactory = new HttpServiceHostFactory {Configuration = configuration}; | |
var webApiRoute = new WebApiRoute(routePrefix, serviceHostFactory, serviceType) | |
{Constraints = new RouteValueDictionary(constraints)}; | |
routes.Add(webApiRoute); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment