Esempio n. 1
0
        private IController CreateControllerInstance(RequestContext requestContext)
        {
            var currentVersion = requestContext.RouteData.Values.ContainsKey(_configuration.ApiVersionKey)
                                     ? requestContext.RouteData.Values[_configuration.ApiVersionKey].ToString()
                                     : _configuration.DefaultControllerVersion;

            var controllerVersionedTypeName = string.Format(
                "{0}{1}Controller",
                ControllerName(requestContext),
                _configuration.TryGetControllerPostfix(currentVersion));
            var controllerDefaultTypeName = string.Format(
                "{0}{1}Controller",
                ControllerName(requestContext),
                _configuration.TryGetControllerPostfix(_configuration.DefaultControllerVersion));

            var typeType = TypesFinder.FindTypeInExecutingAssembly(controllerVersionedTypeName) ??
                           TypesFinder.FindTypeInExecutingAssembly(controllerDefaultTypeName);

            var controller = Activator.CreateInstance(typeType) as IController;

            return(controller);
        }