我试图将SoapClient依赖项注入Foo类,我已经创建了一个提供程序容器,但无法解析该依赖项。
这是我要在其中注入依赖项的类。
namespace App\Services
Class Foo{
public function __construct( )
{
$this->SoapClient = resolve('MySoapClient');
}
public function someMethod($data)
{
$req=$this->SoapClient->getSomething($params);
return $req;
}
}
这是服务提供商
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
use \Illuminate\Foundation\Application;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('MySoapClient', function ($app) {
return new \SoapClient(env('wsdl'));
});
}
}
我只想将SoapClient注入Foo类。上面的代码不起作用,我得到了(类MySoapClient不存在)