doctrine / DoctrineModule

Doctrine Module for Laminas
http://www.doctrine-project.org/projects/doctrine-module.html
MIT License
398 stars 269 forks source link

cannot create instance from AbstractFactory when an alias is called for first instance #246

Closed maxnuf closed 2 years ago

maxnuf commented 11 years ago

I'm seeing an issue when trying to use GoalioRememberMeDoctrineORM It has aliased the doctrine.entitymanager.orm_default to zfcuser_doctrine_em (actually this happens in ZfcUserDoctrineORM, but that is not relevant)

When it tries to get this instance from the servicmanager I receive a service not found exception.

From what I can figure out: when calling $sm->get('zfcuser_doctrine_em'); it will call canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) in AbstractDoctrineServiceFactory with $name = 'doctrine.entitymanager.ormdefault' (note the missing underscore) and $requestedName = 'zfcuser_doctrine_em'

both of which cannot be resolved by the AbstractDoctrineServiceFactory.

superdweebie commented 11 years ago

Yep. Aliases are not supported by DoctrineModule. If you do need to use an alias, you need to create an extra factory to resolve it manually, like this: https://github.com/doctrine/DoctrineORMModule/blob/master/src/DoctrineORMModule/Service/EntityManagerAliasCompatFactory.php

maxnuf commented 11 years ago

That seems a bit cumbersome. Also, the factory your pointing to is deprecated. So is it really the preferred solution?

Atleast you're right, aliasing Doctrine\ORM\EntityManager solves my problem.

superdweebie commented 11 years ago

I agree it's a bit cumbersome, but it's the best compromise at the moment. We're still in the process of working out some new service naming conventions for doctrineModule. See discussion in #233.

Regarding depreciation, I think it's to indicate that this is a temporary thing to help give those who may be using the old alias to change over. @Ocramius will be able to give you a definitive answer.

Ocramius commented 11 years ago

Yes, I marked the factory as deprecated because it's a hack... On 15 May 2013 01:59, "Tim Roediger" notifications@github.com wrote:

I agree it's a bit cumbersome, but it's the best compromise at the moment. We're still in the process of working out some new service naming conventions for doctrineModule. See discussion in #233https://github.com/doctrine/DoctrineModule/issues/233 .

Regarding depreciation, I think it's to indicate that this is a temporary thing to help give those who may be using the old alias to change over. @Ocramius https://github.com/Ocramius will be able to give you a definitive answer.

— Reply to this email directly or view it on GitHubhttps://github.com/doctrine/DoctrineModule/issues/246#issuecomment-17912927 .

maxnuf commented 11 years ago

Thanks, I understand.