private function injectDependencies(RegistryInterface $registry, $entityName = null, EntityManager $entityManager = null)
    {
        if (!($entityManager instanceof EntityManager)) {
            /** @var EntityManager $entityManager */
            $entityManager = $this->container->get('doctrine.orm.entity_manager');
        }

        if ($registry instanceof EntityManagerAwareInterface) {
            $registry->setEntityManager($entityManager);
        }

        if ($registry instanceof EntityRegistry) {
            if ($entityName === null) {
                throw new \Exception('Can\'t load an entity registry without entity name');
            }
            $registry->setEntityRepository($entityManager->getRepository($entityName));
        }

        if ($registry instanceof MongoDBAwareInterface) {
            if ($entityName === null) {
                throw new \Exception('Can\'t load a mongodb registry without entity name');
            }

            $collection = ConnectionFactory::getInstance()->getConnection()->getMongoDatabase()->selectCollection($entityName);
            $registry->setMongoDBCollection($collection);
        }

        if ($registry instanceof ClassAwareInterface) {

            $shortcutParser = new ShortcutNotationParser($entityName);
            $bundle = $this->container->get('kernel')->getBundle($shortcutParser->getBundleName());

            $stackConfiguration = new EntityStackConfiguration($bundle, $shortcutParser->getEntityName());

            if ($registry instanceof MongoDBAwareInterface) {
                $registry->setEntityClass($stackConfiguration->getDocumentClass());
            } else {
                $registry->setEntityClass($stackConfiguration->getEntityClass());
            }
        }
    }