如何使用 Zend_Soap_AutoDiscover 进行依赖注入
我第一次尝试在项目中使用依赖注入容器,但我刚刚发现了一个我不确定如何解决的问题。
该项目提供了一个 SOAP Web 服务,它是在 Zend Framework 的 SOAP 组件之上实现的。其工作方式是定义一个充当服务的类,创建 Zend_Soap_AutoDiscover 或 Zend_Soap_Server 类(对于 WSDL 或类本身,视情况而定),最后,通过 ZF 传递服务类的名称构造函数或通过 setClass 方法。例如:
class MyService {}
$autodiscoveryObj = new Zend_Soap_AutoDiscover();
$autodiscoveryObj->setClass('MyService');
...
问题出在最后一步。我的 DI 容器可以创建一个服务对象并向其中注入所有必需的依赖项。如果我需要自己的代码中的实例,那很好。但是,b/c 您只需将类的名称传递给 ZF,并且您无法自己实际实例化它,它不会通过容器正确实例化,因此它的依赖项永远不会注入。此外,我认为我不能使用任何类型的包装类,因为 ZF 在类上使用反射。
处理这个问题的最佳方法是什么?
I'm trying to use a dependency injection container for the first time in a project, but I just discovered a problem that I'm not sure how to address.
The project provides a SOAP web service, which is implemented atop the SOAP component of Zend Framework. The way this works is that you define a class that acts as your service, you create a Zend_Soap_AutoDiscover or Zend_Soap_Server class (for the WSDL or the class itself, as appropriate), and finally, you pass ZF the name of the service class via the constructor or via the setClass method. For example:
class MyService {}
$autodiscoveryObj = new Zend_Soap_AutoDiscover();
$autodiscoveryObj->setClass('MyService');
...
The problem is with that last step. My DI container can create a service object and inject into it all the required dependencies. That's fine if I need an instance in my own code. However, b/c you just pass the name of the class into ZF, and you don't get to actually instantiate it yourself, it doesn't get properly instantiated through the container so its dependencies are never injected. Further, I don't think I can use any sort of wrapper class, as ZF uses reflection on the class.
What's the best way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Zend_Soap_Server 中,您可以像在 SoapServer 中一样附加/设置对象
In Zend_Soap_Server you can attach/set an object like in SoapServer