I am learning ASP.NET MVC and I created a custom controller factory just for understanding the flow the application.
Below is the code of my custom controller factory.
My question is though the action of the controller is not called within this the action does get executed. How and where does it happen?
How does the Index action get executed when I don't call it from the factory?
using System.Web.Routing;
using System.Web.SessionState;
public class CustomControllerFactory : IControllerFactory
{
public IController CreateController(
RequestContext requestContext,
string controllerName)
{
Type targetType = null;
switch (controllerName)
{
case "first":
case "home":
targetType = typeof(FirstController);
break;
case "second":
targetType = typeof(SecondController);
break;
}
var typ = targetType.GetType();
return Activator.CreateInstance(targetType) as IController;
}
public SessionStateBehavior GetControllerSessionBehavior(
RequestContext requestContext,
string controllerName)
{
return System.Web.SessionState.SessionStateBehavior.Default;
}
public void ReleaseController(IController controller)
{
IDisposable dispose = controller as IDisposable;
if(dispose!= null)
dispose.Dispose();
}
}
And my FirstController
code as below:
public class FirstController : Controller
{
//
// GET: /First/
public ActionResult Index()
{
return Content("first cotnroller");
}
}