I am looking at an example from a book where the author is trying to create a custom controller factory as follows. (Referring to only the CreateController Method)
public IController CreateController(RequestContext requestContext,
string controllerName) {
Type targetType = null;
switch (controllerName) {
case "Product":
targetType = typeof(ProductController);
break;
case "Customer":
targetType = typeof(CustomerController);
break;
default:
requestContext.RouteData.Values["controller"] = "Product";
targetType = typeof(ProductController);
break;
}
return targetType == null ? null :
(IController)DependencyResolver.Current.GetService(targetType);
}
For the default case, the value of the controllerName default case is being set to an existing controller(Product). The reason being given is that this will cause the MVC framework to search for views associated with out fallback controller and not the controller that the user requested. My question is why is it that the views are not searched in the similar way for cases Product and Customer?
You will now be using custom controller factory. But the default view engine is configured to search in the following locations. (for example Home controller, Index action)
You can write your custom view engine and implement it to search on other locations and that way implement the "fallback" location.