protected function build($class, $config)
    {	
        /* @var $reflection ReflectionClass */
        list ($reflection, $dependencies) = $this->getDependencies($class);
        
        $dependencies = $this->resolveDependencies($dependencies, $reflection);
        
        if (empty($config)) {
            return $reflection->newInstanceArgs($dependencies);
        }
        
        if (!empty($dependencies) && $reflection->implementsInterface('Wslim\Common\ConfigurableInterface')) {
            
            // set $config as the last parameter (existing one will be overwritten)
            $dependencies[count($dependencies) - 1] = $config;
            
            return $reflection->newInstanceArgs($dependencies);
        } else {
            $object = $reflection->newInstanceArgs($dependencies);
            foreach ($config as $name => $value) {
                $method = 'set' . ucfirst($name);
                if (method_exists($object, $method)) {
                    $object->$method($value);
                } else {
                    $object->$name = $value;
                }
            }
            
            return $object;
        }
    }