protected override IController GetControllerInstance()

in src/DeloitteDigital.Atlas/Mvc/ControllerFactory.cs [21:48]


        protected override IController GetControllerInstance(RequestContext reqContext, Type controllerType)
        {
            var controller = default(IController);

            // Controller not found
            if (controllerType == null)
                throw new HttpException(404, string.Format(
                    "The controller for path '{0}' could not be found or it does not implement IController.",
                    reqContext.HttpContext.Request.Path));

            // Controller type does not implement IController interface
            if (!typeof(IController).IsAssignableFrom(controllerType))
                throw new ArgumentException(string.Format(
                    "Type requested is not a controller: {0}", controllerType.Name),
                    "controllerType");
            try
            {
                // Create an instance from the controller type and resolve its dependencies
                controller = ServiceLocator.Current.GetService(controllerType) as IController;
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(
                    "Error resolving controller {0}", controllerType.Name), ex);
            }

            return controller;
        }