Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injection in services ? #261

Open
xorgxx opened this issue Oct 5, 2016 · 1 comment
Open

Injection in services ? #261

xorgxx opened this issue Oct 5, 2016 · 1 comment

Comments

@xorgxx
Copy link

xorgxx commented Oct 5, 2016

hi thank for this bundle.
i'm trying to inject in service same services.

 use Ecommerce\EcommerceCoreBundle\Model\CartDetail;
    use JMS\DiExtraBundle\Annotation as DI;

    class CartService
    {
        public $em;
        public $session;
        /**
         * @var CartDetail
         */
        private $cartDetail;

        /**
         * @DI\InjectParams({
         *     "em" = @DI\Inject("doctrine.orm.entity_manager"),
         *     "session" = @DI\Inject("session")
         * })
         */

        /**
         * @param CartDetail $cartDetail
         * @param            $em
         * @param            $session
         */
        public function __construct($em, $session)
        {
            $this->em           = $em;
            $this->session      = $session;
        }
Declaration:
services:
    app.cart.services:
        class: Ecommerce\EcommerceCoreBundle\Controller\Services\CartService
        arguments:
#            - "@router"
#            - "@doctrine.orm.entity_manager"
#            - "@member.user_service"


CONFIG.YML
jms_di_extra:
    locations:
        all_bundles: false
        bundles: [ArticleBundle, EcommerceCoreBundle]
        directories: ["%kernel.root_dir%/../src"]

    automatic_controller_injections:
        properties:
            request: "@request"
            router: "@router"

but i get alwase null
where i get wrong ?
thank any help

@wodka
Copy link
Contributor

wodka commented Oct 12, 2016

for the injection to work you need to have only one docblock:

    /**
     * @DI\InjectParams({
     *     "em" = @DI\Inject("doctrine.orm.entity_manager"),
     *     "session" = @DI\Inject("session")
     * })
     * @param            $em
     * @param            $session
     */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants