JMSDiExtraBundle
JMSDiExtraBundle copied to clipboard
Entity Repository as service dont work ?
im trying
<?php namespace Acme\CoreBundle\Repository;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\Inject;
use Acme\CoreBundle\Entity\User;
/**
* @Service("core.repository.user")
*/
class UserRepository
{
/**
* @Inject("doctrine.orm.entity_manager")
*/
private $entityManager;
public function create(User $user)
{
$this->entityManager->persist($user);
$this->entityManager->flush();
}
}
_@Inject dont work in this case_
im tried also:
<?php namespace Acme\CoreBundle\Repository;
use Doctrine\ORM\EntityRepository;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\Inject;
use Acme\CoreBundle\Entity\User;
/**
* @Service("core.repository.user")
*/
class UserRepository extends EntityRepository
{
public function create(User $user)
{
$this->_em->persist($user);
$this->_em->flush();
}
}
dont work too - but this is probably ok - because parent has container injection
what i need is Repository as service, because im using controllers as services.. its possible with DI Extra or i must register service standard way ? thanks !
As explained in the documentation, @Inject on private and protected properties only works in controllers, not in services: http://jmsyst.com/bundles/JMSDiExtraBundle/master/usage#property-injection
I am not sure you can, since Repository need another service factory (doctrine.orm.default_entity_manager) and JMSDiExtraBundle dont provide a way to config factory_service.
Ping https://github.com/schmittjoh/JMSDiExtraBundle/issues/65