private static Func <string, string> GetNameConverter(UrlNamingConvention convention) { switch (convention) { case UrlNamingConvention.LowerCase: return(s => s.ToLower()); case UrlNamingConvention.SnakeCase: return(s => s.BreakWords().Select(w => w.ToLower()).Join("_")); case UrlNamingConvention.KebabCase: return(s => s.BreakWords().Select(w => w.ToLower()).Join("-")); default: throw new ArgumentOutOfRangeException(nameof(convention), convention, null); } }
public static void SupportGraphController(this HttpConfiguration config, string prefix = "", UrlNamingConvention convention = UrlNamingConvention.LowerCase) { var controllerSelector = new ApiControllerSelector(config, GetNameConverter(convention)); config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector); config.Services.Replace(typeof(IHttpActionSelector), controllerSelector); config.Services.Replace(typeof(IApiExplorer), controllerSelector); config.Routes.MapHttpRoute("default", prefix + "{*path}"); }