使用Symfony 4.1.3声明服务时,如何从自动连线中排除域?

使用Symfony 4.1.3声明服务时,如何从自动连线中排除域?,symfony,service,domain-driven-design,autowired,Symfony,Service,Domain Driven Design,Autowired,我正在使用Symfony 4开发一款轻型DDD应用程序。在我的services.yaml文件中,我将自动布线配置为: services: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically

我正在使用Symfony 4开发一款轻型DDD应用程序。在我的
services.yaml
文件中,我将自动布线配置为:

services:
# default configuration for services in *this* file
_defaults:
    autowire: true      # Automatically injects dependencies in your services.
    autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    public: false       # Allows optimizing the container by removing unused services; this also means
                        # fetching services directly from the container via $container->get() won't work.
                        # The best practice is to be explicit about your dependencies anyway.

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
    resource: '../src/*'
    exclude: '../src/{DataFixtures,Migrations,Tests,Domain/IceCream/IceCream.php,Domain/Cake/Cake.php,Domain/Candy/Candy.php}'
我排除了所有实体,因为它们不是服务。正如您可能已经注意到的,我列出了所有相应的文件,因为当我键入:

exclude: '../src/{DataFixtures,Migrations,Tests,Domain}'
引发运行时异常:
无法自动连线服务:“App\Application\Query\Cake\cakequeryhandler”:方法“\uu construct()”引用接口“App\Domain\CakeRepositoryInterface”的参数“$cakeRepository”,但不存在此类服务。您可能应该将此接口别名为现有的“App\Infrastructure\doctor\Repository\Cake\CakeRepository”服务。
第一个服务是查询处理程序,它不是自动连接的

如何排除整个域而不必键入其中的所有文件


谢谢您的帮助。

正如您直接对我说的,您遇到的运行时错误是:


(1/1)运行时异常
无法自动连接服务“App\Application\Query\Cake\cakequeryhandler”:方法“\uu construct()”的参数“$cakeRepository”引用接口“App\Domain\Cake\CakeRepositoryInterface”,但不存在此类服务。您可能应该将此接口别名为现有的“App\Infrastructure\doctor\Repository\Cake\CakeRepository”服务。

在您的查询处理程序中,您希望注入的服务类型为
App\Domain\Cake\CakeRepositoryInterface

事实上,您已经为您的类别存储库声明了一项名为“
App\Infrastructure\doctor\repository\Cake\CakeRepository”的服务

要解决此问题,您需要在
services.yaml
文件中从界面向存储库添加别名:


App\Domain\Cake\CakeRepositoryInterface:“@App\Infrastructure\Doctrine\Repository\Cake\CakeRepository”

谢谢您的帮助@kinedie我们非常感谢您的感谢,但要感谢堆栈溢出中的某人,最好的方法是接受答案并投票:)