protected function resolveParameter(ReflectionParameter $parameter, $value)
    {
        // If there is no class for the given parameter
        // then some kind of primitive data has been provided
        // and thus we need only to return it.
        $paramClass = $parameter->getClass();
        if ( ! isset($paramClass)) {
            return $value;
        }

        // Fetch the name of the class
        $className = $paramClass->getName();

        // If the value corresponds to the given expected class,
        // then there is no need to resolve anything from the
        // IoC service container.
        if ($value instanceof $className) {
            return $value;
        }

        $container = $this->container();

        // Fail if no service container is available
        if (is_null($container)) {
            $message = sprintf(
                'No IoC service container is available, cannot resolve property "%s" of the type "%s"; do not know how to populate with "%s"',
                $parameter->getName(),
                $className,
                var_export($value, true)
            );
            throw new BindingResolutionException($message);
        }

        // Get the resolved instance for the IoC container
        $instance = $container->make($className);

        // From Laravel 5.4, the Container::make method no longer accepts
        // parameters, which is really sad... Nevertheless, we attempt to
        // resolve this, simply by checking if the instance can be
        // populated with the given value, which is exactly what the
        // `resolveInstancePopulation` method does.
        return $this->resolveInstancePopulation($instance, $parameter, $value);
    }