using System; using System.Web.Mvc; using System.Web.Routing; namespace Umbraco.Web.Mvc { internal static class ControllerFactoryExtensions { /// /// Gets a controller type by the name /// /// /// /// /// /// /// This is related to issue: http://issues.umbraco.org/issue/U4-1726. We already have a method called GetControllerTypeInternal on our MasterControllerFactory, /// however, we cannot always guarantee that the usage of this will be a MasterControllerFactory like during unit tests. So we needed to create /// this extension method to do the checks instead. /// internal static Type GetControllerTypeInternal(this IControllerFactory factory, RequestContext requestContext, string controllerName) { if (factory is MasterControllerFactory controllerFactory) return controllerFactory.GetControllerTypeInternal(requestContext, controllerName); //we have no choice but to instantiate the controller var instance = factory.CreateController(requestContext, controllerName); return instance?.GetType(); } } }