private function createInstance($definition, $arguments, $shared)
    {
        if (is_string($definition)) {
            return new $definition(...$arguments);
        }

        if (is_callable($definition)) {
            return $definition(...$arguments);
        }

        if (is_object($definition)) {
            if ($shared) {
                return $definition;
            }
            else {
                return new $definition(...$arguments);
            }
        }

        throw new \RuntimeException('Invalid service definition!');
    }