using System;
using System.Web.Mvc;
using System.Web.Routing;
using StructureMap;

namespace ExpenseTracking
{
    public class CustomControllerFactory : DefaultControllerFactory
    {
        #region IControllerFactory Members
        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            IController controller = base.CreateController(requestContext, controllerName);
            return controller;
        }

        //public System.Web.SessionState.SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
        //{
        //    return SessionStateBehavior.Default;
        //}
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            try
            {
                return ObjectFactory.GetInstance(controllerType) as Controller;
            }
            catch 
            {
                return null;
            }
        }

        #endregion
    }
}