###前提・実現したいこと
Symfony3.3でDIの学習をしています。
実現したことはアノテーションによるサービスの登録です。
行ったことは以下です。
jms/di-extra-bundleをインストール
composer require jms/di-extra-bundle
AppKernelに以下2行を追記
class AppKernel extends Kernel { public function registerBundles() { $bundles = [ 〜中略〜 new JMS\DiExtraBundle\JMSDiExtraBundle(), new JMS\AopBundle\JMSAopBundle(), ];
サービスクラスとして使用する予定のファイルに以下を定義
use JMS\DiExtraBundle\Annotation as DI; /** * @DI\Service(name="app.service_annotation_test") */ class ServiceAnnotationTest {
確認
bash
1php bin/console debug:container
この時点でサービスが登録されていません。
###発生している問題・エラーメッセージ
You have requested a non-existent service "app.service_annotation_test". # 以下の行がエラーになる $service = $this->get('app.service_annotation_test');
###試したこと
app/config/services.ymlに以下(一番下のcalls:)を追記
AppBundle\Controller\: resource: '../../src/AppBundle/Controller' public: true tags: ['controller.service_arguments'] calls: - [setContainer, ["@service_container"]]
###補足情報(言語/FW/ツール等のバージョンなど)
php7.0
Symfony3.3
jms/di-extra-bundle 1.9
あなたの回答
tips
プレビュー