[英]How inject Memcached class to service Symfony2
I want ot inject Memcached class into my servcie by setter injection. 我想通过setter注入将Memcached类注入到我的服务中。 But I dont know how I can do this.
但是我不知道该怎么做。 Can somebody help me?
有人可以帮我吗? Here what I already tried:
这是我已经尝试过的:
<service id="uber.memcached" class="Bundle" >
<call method="setMemcached">
\Memcached
</call>
</service>
Configure your services into service.xml file 将服务配置到service.xml文件中
// memcached service
<service id="memcached" class="Memcached" />
// memcached injection
<service id="uber.memcached" class="App\Bundle\Foo">
<call method="setMemcached">
<argument type="service" id="memcached" />
</call>
</service>
And then, use it on your service class 然后,在您的服务等级上使用它
// App/Bundle/Foo.php
namespace App\Bundle;
Class Foo {
public function setMemcached($service) {
// your code
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.