diff --git a/src/Di/DiAbstractServiceFactory.php b/src/Di/DiAbstractServiceFactory.php index 83967d6a..9f030e18 100644 --- a/src/Di/DiAbstractServiceFactory.php +++ b/src/Di/DiAbstractServiceFactory.php @@ -51,10 +51,18 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $ */ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { - return $this->instanceManager->hasSharedInstance($requestedName) + if ($this->instanceManager->hasSharedInstance($requestedName) || $this->instanceManager->hasAlias($requestedName) || $this->instanceManager->hasConfig($requestedName) || $this->instanceManager->hasTypePreferences($requestedName) - || $this->definitions->hasClass($requestedName); + ) { + return true; + } + + if (! $this->definitions->hasClass($requestedName) || interface_exists($requestedName)) { + return false; + } + + return true; } }