I wanted to use solution which was described in this answer but it doesn't work. Symfony2/JmsDIExtraBundle Injecting repository into service using annotations
I am using symfony 3 and my use case you can find below:
namespace AppBundle\Repository;
use JMS\DiExtraBundle\Annotation as DI;
use UserBundle\Repository\UserRepository as BaseUserRepository;
/**
* @DI\Service("user_repository", factoryService = "doctrine", factoryMethod="getRepository", factoryMethodArguments={
* "persistentObjectName" = "AppBundle\Model\User"
* } )
*/
class UserRepository extends BaseUserRepository
{
}
Base class:
namespace UserBundle\Repository;
use Doctrine\ODM\MongoDB\DocumentRepository;
use UserBundle\Model\User;
abstract class UserRepository extends DocumentRepository
{
public function save(User $user)
{
$dm = $this->getDocumentManager();
$dm->persist($user);
$dm->flush($user);
}
}
And the command where I want to use UserRepository
class CreateAdminCommand extends BaseCreateAdminCommand
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->userRepository = $this->getContainer()->get('user_repository');
}
}
Next, when I want to execute my command I am getting this error:
[Doctrine\Common\Annotations\AnnotationException] [Creation Error] The annotation @DI\Service declared on class AppBundle\Repository\UserRepository does not have a property named "factoryService". Available properties: id, parent, public, scope, shared, deprecated, decorates, decoration_inner_name, abstract, environments
I agree with this error because I cannot find such property in Service annotation. So in my opinion it shouldn't work but it was described on another question and github as correct solution. I don't understand something here, could you help me Guys?