private static ResourceContext CreatePrimaryResourceContext(RouteValueDictionary routeValues,
                                                                    IControllerResourceMapping controllerResourceMapping, IResourceContextProvider resourceContextProvider)
        {
            var controllerName = (string)routeValues["controller"];

            if (controllerName != null)
            {
                var resourceType = controllerResourceMapping.GetResourceTypeForController(controllerName);
                if (resourceType != null)
                {
                    return(resourceContextProvider.GetResourceContext(resourceType));
                }
            }

            return(null);
        }
        private static ResourceContext CreatePrimaryResourceContext(HttpContext httpContext, IControllerResourceMapping controllerResourceMapping,
                                                                    IResourceContextProvider resourceContextProvider)
        {
            Endpoint endpoint = httpContext.GetEndpoint();
            var      controllerActionDescriptor = endpoint?.Metadata.GetMetadata <ControllerActionDescriptor>();

            if (controllerActionDescriptor != null)
            {
                Type controllerType = controllerActionDescriptor.ControllerTypeInfo;
                Type resourceType   = controllerResourceMapping.GetResourceTypeForController(controllerType);

                if (resourceType != null)
                {
                    return(resourceContextProvider.GetResourceContext(resourceType));
                }
            }

            return(null);
        }