public function singletonInstance(InstanceFactory $factory, $className)
{
if (isset($this->instances[$className])) {
return $this->instances[$className];
}
$instance = $factory->createInstance($this, $className);
$this->instances[$className] = $instance;
return $instance;
}