Why the Service Locator is a Anti-Pattern in the following example?

▼魔方 西西 提交于 2019-12-03 16:35:39

I don't think that what you've built does implement the service locator pattern. If you had so, there would be a global "registry" somewhere.

What I see is basically a factory class (App\Controller\Action\Helper\Service) with dependencies, which are injected via the ctor. So your class does not know where its dependencies came from and it's also not responsible for creating them (which is a good thing!).

Correct me if I'm wrong. :)

BTW: That's also the reason why you should not pass around your dependency injection container. It turns into a service locator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!