Reputation: 1337
I'm using JMSDiExtraBundle in my Symfony2 project.
Here is my the problem:
Repository.php
abstract class Repository extends DocumentRepository implements ReadOnlyRepositoryInterface {
protected $dm;
protected $repo;
protected $query;
/**
* @InjectParams({
* "dm" = @Inject("doctrine.odm.mongodb.document_manager")
* })
*/
public function __construct(DocumentManager $dm) {
$this->dm = $dm;
parent::__construct($dm, $this->dm->getUnitOfWork(), new ClassMetadata($this->getDocumentName()));
$this->query = $this->dm->createQueryBuilder($this->getDocumentName());
}
}
PostRepository.php
/**
* @Service("post_repository")
*/
class PostRepository extends Repository implements PostRepositoryInterface {
private $uploader;
/**
* @InjectParams({
* "dm" = @Inject("doctrine.odm.mongodb.document_manager"),
* "uploader" = @Inject("uploader"),
* })
*/
public function __construct(DocumentManager $dm, UploaderService $uploader) {
parent::__construct($dm);
$this->uploader = $uploader;
}
}
As can be seen, PostRepository requires 2 dependency : DocumentManager (later injected to Repository as parent) and Uploader.
But it seems that Symfony does something which making it assumed that PostRepository needed 3 dependency : DocumentManager, DocumentManager (again) and Uploader, which off course gives an error since I explicitly stated that the second parameter is required to be an Uploader instance.
Here's from appDevDebugProjectContainer.xml
:
<service id="post_repository" class="BusinessLounge\BlogBundle\Repository\PostRepository">
<argument type="service" id="doctrine_mongodb.odm.default_document_manager"/>
<argument type="service" id="doctrine_mongodb.odm.default_document_manager"/>
<argument type="service" id="uploader"/>
</service>
and appDevDebugProjectContainer.php
:
/**
* Gets the 'post_repository' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return BusinessLounge\BlogBundle\Repository\PostRepository A BusinessLounge\BlogBundle\Repository\PostRepository instance.
*/
protected function getPostRepositoryService()
{
$a = $this->get('doctrine_mongodb.odm.default_document_manager');
return $this->services['post_repository'] = new \BusinessLounge\BlogBundle\Repository\PostRepository($a, $a, $this->get('uploader'));
}
Is this an intended behavior? Or a bug perhaps? Or I did something wrong?
Need advice!
Upvotes: 0
Views: 240
Reputation: 2191
You can just remove the @InjectParams on your abstract parent class, since it is never instantiated anyways. Then only the things you need are injected in your real service.
Upvotes: 2