缩略语 在这种情况下,你可以通过<编码>网页注入受扶养人,你不需要将战略定义为服务。
每项战略都可能取决于不同的目标,因此,我猜测你可以将其编成<代码>。 集装箱 意识到。 这里的例子就是如何做到这一点。
// This is the page.service class
class MyPageService {
public function render(PageTypeInterface $page_type) {
$page_type->setContainer($this->container);
// do stuff
}
}
// This is the type strategy
class MyStrategyType extends ContainerAware implements PageTypeInterface {
// you can access the container after MyPageService has injected it.
}
因此,每项战略基本上都将.ContainerA和注入该集装箱。
如果你们的所有战略都依赖同样的服务,我就把这些服务而不是整个集装箱注入。
class MyPageService {
public function render(PageTypeInterface $page_type) {
$page_type->setService($this->container->get( my_service ));
// do stuff
}
}