0

After updating symfony from 3.4 to 4.4(without flex) i am getting this error The "tactician.commandbus" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

I am injecting depnedeicies to controller using jms/di-extra-bundle

class MngmtController extends AbstractFOSRestController
{
   /**
     * @var CommandBus
     */
    private $commandBus;

    /**
     * @var CommandBus
     */
    private $mngmtCommandBus;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @var MngmtService
     */
    private $mngmtService;

    /**
     * @param ContainerInterface $container
     * @param CommandBus         $commandBus
     * @param CommandBus         $mngmtCommandBus
     * @param LoggerInterface    $logger
     * @param MngmtService       $mngmtService
     *
     * @DI\InjectParams({
     *     "container" = @DI\Inject("service_container"),
     *     "commandBus" = @DI\Inject("tactician.commandbus"),
     *     "mngmtCommandBus" = @DI\Inject("tactician.commandbus.mngmt"),
     *     "logger" = @DI\Inject("monolog.logger"),
     *     "mngmtService" = @DI\Inject("app.services.mngmt_service"),
     * })
     */
    public function __construct(
        ContainerInterface $container,
        CommandBus $commandBus,
        CommandBus $mngmtCommandBus,
        LoggerInterface $logger
        MngmtService $mngmtService,
    ) {
        $this->container = $container;
        $this->commandBus = $commandBus;
        $this->mngmtCommandBus = $mngmtCommandBus;
        $this->logger = $logger;
        $this->mngmtService = $mngmtService;
    }

I have tried adding this in services.yml, but didn't help

   _defaults:
        public: true
   
    League\Tactician\CommandBus:
        alias: 'tactician.commandbus'
        public: true
    
    Psr\Log\LoggerInterface:
        alias: 'monolog.logger'
        public: true

I am following older directory structure not updated to sf4/flex directory structure, Please help me with the above error

  • To start with, your [alias definition](https://symfony.com/doc/current/service_container/alias_private.html#aliasing) is backwards. The actual aliases goes first and then the service being aliased. But the problem goes much deeper. You probably don't have any command bus services defined. You can use `bin/console debug:container` to see what services you do have. Symfony now uses autowiring to wire up services. The di-extra bundle is not really used anymore. Basically you probably want to enable autowire and get rid of the DI annotation stuff. But I don't think it will be easy. – Cerad Jun 17 '22 at 20:59
  • You might also try [this technique](https://stackoverflow.com/questions/55042137/how-to-make-loggerinterface-service-public-in-symfony-4/55045727#55045727) for declaring your services public. You would have to do this for many of your services but it might help you put off refactoring. – Cerad Jun 17 '22 at 21:05
  • @Cerad Thanks for your time, yes command bus service is availiable in container(```bin/console debug:container```) have chnaged the alias definition and set autowire and autoconfigure to true but still the same error and its same issue with all the parameters injected in the constructor. Have seen your answer on the other technique before asking this question but i haven't updated my AppKernel.php after updating to sf 4.4 version i am still having older AppKernel, app/config and directory structure. – user_fullstack Jun 18 '22 at 03:41
  • @Cerad If i remove DI annotations will end up with too few argumants passed into the ```__construct(), 0 passed in /tmp/var/cache/dev/jms_diextra/controller_injectors/AppBundleControllerMngmtController.php on line 13 and exactly 7 expected"} ``` – user_fullstack Jun 18 '22 at 03:42
  • @Cerad and also have many service classes need to set public for each servie, the list will be very big – user_fullstack Jun 18 '22 at 12:57
  • It's not going to be fun especially if this is a large application. You need to get your controller defined as a service. That is what the DI bundle was doing and why you get the too few arg errors. I guess the basic question is why have you chosen to upgrade? Why not just stay where you are at? If the app is important and you plan on using it for years then you might just need to bite the bullet and refactor it. – Cerad Jun 18 '22 at 13:40
  • @Cerad As symfony 3.4 support ended, we planeed to upgrade to next LTS version 4.4. Yes the aplication is big especially the DI part and configuration. It works if i set each service to true in APpKernel process method but the list is very big. Is there any alternatives you could suggest to make this work keeping the jms-di/extra bundle – user_fullstack Jun 18 '22 at 14:01
  • You might try grabbing all the services and then just loop through and set each one to public. I don't think it will hurt anything. Of course 4.4 is also getting close to end of life. – Cerad Jun 18 '22 at 14:15
  • @Cerad yes, may be another 6 months need to move to 5.4, by that time need to remove the dependency on jms-di/extra bundle and start using DI in symfony way. Now will loop through the all services, won't it decrease performance ? – user_fullstack Jun 18 '22 at 14:30
  • @Cerad even grabbing all services form container and setting them public causes many errors like ```The service "templating.loader.cache" has a dependency on a non-existent service "templating.loader.wrapped"``` or ```Class Psr\SimpleCache\CacheInterface does not exist``` there are many more. So its difficult to find which services to set public – user_fullstack Jun 18 '22 at 14:36
  • Oh well. It was worth a shot. Performance would not have been impacted though I figured that even if you got past this point then you would just run into more problems. Maybe someone else will come by and offer a useful suggestion. Personally I would just jump to PHP 8.1 and Symfony 6.1 and be done with it. Depending on your third party bundles it's really just a case of copy/paste/tweak. Good luck. – Cerad Jun 18 '22 at 14:44
  • @Cerad Will see how it goes, thanks for your time and suggestion – user_fullstack Jun 18 '22 at 16:49
  • @Cerad could you please have a look on this https://stackoverflow.com/questions/72679461/class-web-profiler-controller-profiler-and-class-fos-rest-exception-twig-cont it would be helpful if you provide any suggestions. Thank you. – user_fullstack Jun 20 '22 at 19:05
  • Thanks for the invite but I'm going to pass. There are just too many unknowns with respect to how your app has been setup. If I had access to the complete code I could poke around and perhaps see what is going on. `app/console debug:container web_profiler.controller.profiler` should show the controller service. Why it is not there is anyone's guess. – Cerad Jun 20 '22 at 19:39
  • @Cerad output of the command ```Service ID web_profiler.controller.profiler Class Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController Tags - Public yes Synthetic no Lazy no Shared yes Abstract no Autowired no Autoconfigured no``` – user_fullstack Jun 21 '22 at 04:38
  • @Cerad have executed thes commands https://stackoverflow.com/a/58853809/3158294 and has same output. – user_fullstack Jun 21 '22 at 04:49

0 Answers0