8000 Controller service argument binding with multiple EntityManager · Issue #28091 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Controller service argument binding with multiple EntityManager #28091
Closed
@abienvenu

Description

@abienvenu

Symfony version(s) affected: 3.4.13

Description
Binding controller service argument used to work in Symfony 3.4.12, but not in 3.4.13 anymore.

How to reproduce
service.yml :

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: true
        bind:
            $em: '@doctrine.orm.my_entity_manager'

    My\FrontofficeBundle\Controller\:
        resource: '../../Controller'
        tags: ['controller.service_arguments']

The controller action is defined as :

public function indexAction(Request $request, EntityManagerInterface $em)
{
...

I have several entity managers defined in config.yml, and my_entity_manager is not the default one.
In Symfony 3.4.13, the controller action gets the default entity manager. I would expect it to be passed my_entity_manager, like in Symfony 3.4.12.

Possible Solution

A solution is to inject the entity manager via a controller constructor :

	public function __construct(EntityManagerInterface $em)
	{
		$this->em = $em;
	}

Then we get the correct entity manager.
But is this behaviour expected ? And is it expected that the behaviour changed between minor Symfony versions ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0