protected function buildFromConfig($id, array $config)
    {
        if (empty($config['__class'])) {
            $config['__class'] = $id;
        }
        if (empty($config['__class'])) {
            throw new NotInstantiableException(var_export($config, true));
        }
        /* @var $reflection ReflectionClass */
        [$reflection, $dependencies] = $this->getDependencies($config['__class']);
        unset($config['__class']);

        if (isset($config['__construct()'])) {
            foreach (array_values($config['__construct()']) as $index => $param) {
                $dependencies[$index] = $param;
            }
            unset($config['__construct()']);
        }

        $dependencies = $this->resolveDependencies($dependencies, $reflection);
        if (!$reflection->isInstantiable()) {
            throw new NotInstantiableException($reflection->name);
        }

        $object = $reflection->newInstanceArgs($dependencies);

        $config = $this->resolveDependencies($config);

        return static::configure($object, $config);
    }