如何轻松获取任意类中的服务容器?
我想轻松地在任何地方访问我的控制器容器。有没有“官方”的方式来做到这一点?
我打算在返回容器的包类(或控制器类)中创建一个静态访问函数。容器将在控制器的构造函数中初始化。
I want to easily get access to my Controller container everywhere. Is there an "official" way for doing this ?
I intend to create a static access function in the bundle class (or controller class) that returns the container. The container would be initialized in the controller's constructor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,没有“官方”方法可以实现此目的,并且强烈建议不要这样做。您建议的方法会起作用,但您会发现学习如何使用服务会更有用。
No, there is no "official" way to accomplish this and it is strongly discouraged. Your suggested approach will work but you will find it to be more useful to learn how to use Services.