You can do this using Routing, and keeping the controllers in separate namespaces.
MapRoute lets you specify which namespace corresponds to a route.
Example
Given this controllers
namespace CustomControllerFactory.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return new ContentResult("Controllers");
}
}
}
namespace CustomControllerFactory.ServiceControllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return new ContentResult("ServiceControllers");
}
}
}
And the following routing
routes.MapRoute(
"Services",
"Services/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "CustomControllerFactory.ServiceControllers" } // Namespace
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "CustomControllerFactory.Controllers"} // Namespace
);
You should expect the following responses
/Services/Home
ServiceController
/Home
Controllers
ContentResult
or any non-view result, just remember if you decide to return any sort of view, you will need to create a custom view engine. – Owl