G
G
grabbee2021-11-27 19:18:39
symfony
grabbee, 2021-11-27 19:18:39

How to understand the strange behavior of services in Symfony?

I declare a named service

some.easy_service:
    class: SomeVendor\Services\EasyService
    arguments:
      ...


Then I register it in another service
SomeVendor\SomeBundle\Services\AnotherService:
    arguments:
      $easyService: '@some.easy_service'
      ...


I get an error

Cannot autowire service "SomeVendor\SomeBundle\Services\AnotherService": argument "$easyService" of method "__construct()" references class "SomeVendor\Services\EasyService" but no such service exists. You should maybe alias this class to the existing "some.easy_service" service.


He sees it and does not see it at the same time. Autowiring of services is enabled. But the alias is not declared, because I directly registered it. Why can't he see him straight away?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2021-11-27
@grabbee

There are two options:
1) in a certain version, the declaration through the class is outdated, it is necessary through alias
https://symfony.com/doc/current/service_container/...
2) the container cache is not regenerated
I am generally a supporter of full namespaces, without aliases in configs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question