gpt4 book ai didi

dependency-injection - 通过 services.yml 将自定义实体存储库类传递给服务

转载 作者:行者123 更新时间:2023-12-04 05:59:26 24 4
gpt4 key购买 nike

我尝试通过 services.yml 使用自定义存储库加载我的服务

我现在有:

parameters:
job_entity_name: Marek\JobeetBundle\Entity\Job
category_entity_name: Marek\JobeetBundle\Entity\Category

services:
job_metadata:
class: Doctrine\ORM\Mapping\ClassMetaData
arguments:
name: [%job_entity_name%]
category_metadata:
class: Doctrine\ORM\Mapping\ClassMetaData
arguments:
name: [%category_entity_name%]
job_repo:
class: Marek\JobeetBundle\Repositories\JobRepository
arguments:
em: [@doctrine.orm.entity_manager]
class: [@job_metadata]
category_repo:
class: Marek\JobeetBundle\Repositories\CategoryRepository
arguments:
em: [@doctrine.orm.entity_manager]
class: [@category_metadata]
job_service:
class: Marek\JobeetBundle\JobService
arguments:
jobRepo: [@job_repo]
categoryRepo: [@category_repo]

错误:

Notice: Array to string conversion in D:\Devel\symfony2\jobeet\vendor\doctrine\lib\Doctrine\ORM\Mapping\ClassMetadata.php line 66



我放弃。有人可以帮忙吗?

[编辑]

当然我的架构不好,正确的是:
services:
job_metadata:
class: Doctrine\ORM\Mapping\ClassMetaData
arguments:
name: "Marek\JobeetBundle\Entity\Job"
category_metadata:
class: Doctrine\ORM\Mapping\ClassMetaData
arguments:
name: "Marek\JobeetBundle\Entity\Category"
job_repo:
class: Marek\JobeetBundle\Repositories\JobRepository
arguments:
em: @doctrine.orm.entity_manager
class: @job_metadata
category_repo:
class: Marek\JobeetBundle\Repositories\CategoryRepository
arguments:
em: @doctrine.orm.entity_manager
class: @category_metadata
job_service:
class: Marek\JobeetBundle\JobService
arguments:
jobRepo: @job_repo
categoryRepo: @category_repo

最佳答案

在这个答案中,您将找到一种将存储库定义为服务的更好方法(即使用 factory-services 和 factory-methods)。

Injecting repositories

关于dependency-injection - 通过 services.yml 将自定义实体存储库类传递给服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9100585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com