我正在尝试通过 DI 将实体注入到服务中。
实体是通过 Doctrine-JSON-ODM-library ( https://github.com/dunglas/doctrine-json-odm )从数据库中的 JSON 字段(从用户请求中查询)创建的。
我通常会编写一个上下文类,它将请求和存储库返回依赖关系(如此处所述https://blogs.cuttingedge.it/steven/posts/2015/code-smell-injecting-runtime-data-into -组件/)。然而,由于我的依赖依赖于树结构中深度嵌套的数据,这似乎不可行。
/* Doctrine-Entity queried from DB with User-Request-Parameters */
class Page
{
/**
* @var Slot[]
* @ORM\Column(type="json_document", options={"jsonb": true})
*/
private $slots = [];
}
/* First level of nesting */
class Slot
{
/** @var Components[] */
private $components;
}
/* Entity to be injected */
class Component
{
// multiple data-fields
}
// Service which will need to work with the Component-Data
class ComponentRenderService
{
// multiple functions which all need (read)-access to the
// Component-data
}
如何解决通过深度嵌套结构创建的依赖项?