private function createInstance($nid, array $args) {
        $rule = $this->makeRule($nid);

        // Cache the instance or its factory for future use.
        if (empty($rule['shared'])) {
            $factory = $this->makeFactory($nid, $rule);
            $instance = $factory($args);
            $this->factories[$nid] = $factory;
        } else {
            $instance = $this->createSharedInstance($nid, $rule, $args);
        }
        return $instance;
    }