private function prepareSingletonBindingClosure($id, $blueprint, $dependencies): Closure
    {
        $binding = $this->bindings[$id];
        $instance = $blueprint;

        if ($blueprint instanceof ReflectionClass) {
            foreach ($dependencies as $key => $dependency) {
                if ($dependency instanceof Closure) {
                    $dependencies[$key] = $dependency();
                }
            }
            $instance = $blueprint->newInstanceArgs($dependencies);
        }
        if ($blueprint instanceof Closure) {
            $instance = $blueprint();
        }
        // If blueprint is supplied as a class name.
        if (is_string($blueprint)) {
            $instance = new $blueprint;
        }
        // Singletons won't need these any longer so free up the memory.
        unset($binding['dependencies'], $binding['reflector']);

        return $this->cache[$id] = function () use ($instance) {
            return $instance;
        };
    }