Symfony2 프로젝트에서 JMSDiExtraBundle을 사용하고 있습니다.Symfony2 JMSDiExtraBundle 하위 서비스 종속성 오류
/**
* @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;
}
}
에서 볼 수있는 바와 같이
는, PostRepository 필요한 2 종속 PostRepository.php
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());
}
}
: 여기
내 문제입니다 DocumentManager (나중에 Repository에 부모로 주입 됨) 및 업 로더.그러나 Symfony는 PostRepository가 DocumentManager, DocumentManager (다시) 및 업 로더 중 하나 인 것으로 가정하는 것으로 보이는 것 같습니다. 두 번째 매개 변수가 업 로더가되어야한다는 것을 명시 적으로 명시 했으므로 물론 오류가 발생합니다. 예.
여기 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>
및 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'));
}
이 의도 된 행동인가를? 아니면 아마도 버그? 아니면 내가 잘못한거야?
자문이 필요합니다.
왜 추상 클래스에 주사를 추가 하시겠습니까? 어쨌든 추상화 할 수 없으므로 추상 부모 클래스에서 @InjectParams 부분을 제거하십시오. – m0c
버그처럼 보입니다. 신고해야할까요? –
@ m0c 그것은 행동에 대한 나의 호기심을 실제로 해결하지는 않지만 아주 좋은 지적입니다. 하지만 당신의 대답은 그날을 구 했습니 다. :) –