/// <summary> /// Creates routes for the specified root controller and all other controllers /// in the same namespace or any sub-namespace, in the same assembly, and prepends the /// provided base route to the URL of each created route. /// </summary> /// <param name="routes">A collection of routes for the application.</param> /// <param name="baseRoute">A base route to prepend to the URL of each created route. This parameter can be null.</param> /// <param name="rootController">The root controller for the provided base route.</param> /// <param name="settings">A settings object that customizes the route creation process. This parameter can be null.</param> /// <returns>The created routes.</returns> public static ICollection <Route> MapCodeRoutes(this RouteCollection routes, string baseRoute, Type rootController, CodeRoutingSettings settings) { if (routes == null) { throw new ArgumentNullException("routes"); } if (rootController == null) { throw new ArgumentNullException("rootController"); } var registerSettings = new RegisterSettings(null, rootController) { BaseRoute = baseRoute, Settings = settings }; Route[] newRoutes = RouteFactory.CreateRoutes <Route>(registerSettings); foreach (Route route in newRoutes) { routes.Add(route); } if (newRoutes.Length > 0 && registerSettings.Settings.EnableEmbeddedViews) { EmbeddedViewsVirtualPathProvider.RegisterAssembly(registerSettings); } return(newRoutes); }
/// <summary> /// Enables namespace-aware views location. Always call after you are done adding view engines. /// </summary> /// <param name="engines">The view engine collection.</param> public static void EnableCodeRouting(this ViewEngineCollection engines) { if (engines == null) { throw new ArgumentNullException("engines"); } for (int i = 0; i < engines.Count; i++) { IViewEngine engine = engines[i]; if (engine.GetType() == typeof(Web.Mvc.ViewEngineWrapper)) { continue; } engines[i] = new Web.Mvc.ViewEngineWrapper(engine); } EmbeddedViewsVirtualPathProvider.RegisterIfNecessary(); }