根据马可的Pivetta看法这个,这个老问题 和我的回答的另一个问题
我在询问自己在Zend Framework 2应用程序中使用我们的服务的更好方法.
实际上我们可以ServiceLocatorAwareInterface结合使用ServiceLocatorAwareTrait.事实上在ZF3中,服务定位器将被移除在控制器中它们可能也会删除此接口,或建议不使用它的人,这是有道理的.
我看到我们的服务如何构建的唯一方法是:
不要在服务中使用ServiceLocator,请使用DependancyInjection.
问题是 :
有些项目非常大,你要么:
您可能需要在服务中使用的一些示例:
也许对于其中的一些观点,它们可以通过我不知道的技巧来解决.
我的问题是:
在一个服务中拥有15个或更多Dependancies并放弃ServiceLocator,在控制器中,还是在服务中,这是一个好习惯吗?
从评论中编辑
为了说明我的观点,我粘贴了一个构造函数:
public function __construct(
ToolboxService $toolboxService,
EntityService $entityService,
UserService $userService,
ItemService $itemService,
CriteriaService $criteriaService,
Import $import,
Export $export,
PhpRenderer $renderer
) {
$this->toolboxService = $toolboxService;
$this->entityService = $entityService;
$this->userService = $userService;
$this->emOld = $this->toolboxService->getEmOld();
$this->emNew = $this->toolboxService->getEmNew();
$this->serviceLocator = $this->toolboxService->getServiceLocator();
$this->itemService = $itemService;
$this->criteriaService = …Run Code Online (Sandbox Code Playgroud)