1
這裏是我的代碼:當我建立我的第一個依賴注入的類在Laravel 5.3我得到了一個BindingResolutionException
class WechatServiceProvider extends ServiceProvider
{
// Bootstrap the application services.
// @return void
public function boot()
{
//
}
// Register the application services.
// @return void
public function register()
{
$this->app->bind('App\Http\Wechat',function()
{
$arr = array('token'=>'foo') ;
return new Wechat($arr) ;
});
}
}
嘗試自動注入這裏的依賴
class WechatController extends Controller
{
protected $wechatObj;
public function __construct(Wechat $wechatObj)
{
$this->wechatObj = $wechatObj;
}
...
}
在app \ HTTP \微信.PHP
public function __construct($options)
{
$this->token = isset($options['token'])?$options['token']:'';
$this->encodingAesKey = isset($options['encodingaeskey'])?$options['encodingaeskey']:'';
$this->appid = isset($options['appid'])?$options['appid']:'';
$this->appsecret = isset($options['appsecret'])?$options['appsecret']:'';
$this->agentid = isset($options['agentid'])?$options['agentid']:'';
$this->debug = isset($options['debug'])?$options['debug']:false;
$this->logcallback = isset($options['logcallback'])?$options['logcallback']:false;
}
錯誤堆棧
- BindingResolutionException在Container.php線850: 無法解析依賴性解決[參數#0 [$選項]]類應用\ HTTP \微信
- 在Container.php線850
- 在容器 - > resolveNonClass在Container.php線(對象(ReflectionParameter))817
- 在容器 - > getDependencies(陣列(對象(ReflectionParameter)),陣列())在Container.php線790
我認爲你需要跑這裏來了'作曲家自卸autoload' –