I assume PageType
is an example of a strategy class. In this case, you can inject page.service
dependencies, and you will not need to define strategies as services.
Each strategy probably depends on different objects, so I think you could make them ContainerAware
. Here is an example of how to do it.
// 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. }
Thus, each strategy will expand ContainerAware
, and page.service
will introduce a container.
EDIT
If all your strategies depend on the same services, I would introduce them instead of the entire container.
class MyPageService { public function render(PageTypeInterface $page_type) { $page_type->setService($this->container->get('my_service'));
gilden
source share