Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DI] falsely removes a service in some conditions #58087

Open
@unnamed777

Description

@unnamed777

Symfony version(s) affected

6.4.10

Description

The problem in short: DI removes doctrine repository, which is used in non-shared services, and throws an exception "You have requested a non-existent service "App\Repository\ChannelRepository"" under certain circumstances.

I stumbled upon this issue on working project, got rid of everything unrelated and tried to minimize the code. So, I have a Console command, which usesCheckEmail service:

#[AsCommand('app:check-inbox','Check inbox and process emails')]class CheckInboxCommandextends Command{protectedCheckEmail$action;publicfunction__construct(CheckEmail$command    )    {parent::__construct();    }}

CheckEmail is a public non-shared service, which depends on two another services (processors):

<?phpnamespaceApp\Action;useApp\Processor;class CheckEmail{publicfunction__construct(\App\Processor\FirstProcessor$firstProcessor,\App\Processor\SecondProcessor$secondProcessor,    ) {    }}

And two similar processors, which uses serviceChannelRepository:

<?phpnamespaceApp\Processor;useApp\Repository\ChannelRepository;usePsr\Log\LoggerInterface;class FirstProcessor{publicfunction__construct(LoggerInterface$logger,ChannelRepository$channelRepository,    ) {    }}
<?phpnamespaceApp\Processor;useApp\Repository\ChannelRepository;usePsr\Log\LoggerInterface;class SecondProcessor{publicfunction__construct(//LoggerInterface $logger,ChannelRepository$channelRepository,    ) {    }}

If I try to build container (clear cache or open/ in browser), I get error "You have requested a non-existent service "App\Repository\ChannelRepository"". But there are some changes (any of them), when everything starts working:

How to reproduce

PHP 8.1 is required

  • Clonehttps://github.com/unnamed777/project_issue
  • symfony composer install. You'll get the the same error, but it's ok for now.
  • symfony serve
  • Open link provided by Symfony CLI. The error is appeared.
  • Opensrc/Processor/FirstProcesssor.php and comment line with$logger in constructor. Refresh page, the error is gone.
  • Undo previous change. Opensrc/Controller/DevController.php and uncommend line 11 (CheckEmail $action). The error is gone.
  • Try other actions from description part.

Possible Solution

No response

Additional Context

Comparison of a log ofSymfony\Component\DependencyInjection\Compiler shows the difference only in one line (it exists when the problem is here):

Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass: Inlined service "App\Repository\ChannelRepository" to "App\Processor\FirstProcessor".

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp