2016-12-28 1 views
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) ; 
     }); 
    } 
} 

試しautoにここ

class WechatController extends Controller 
{ 
    protected $wechatObj; 

    public function __construct(Wechat $wechatObj) 
    { 
     $this->wechatObj = $wechatObj; 
    } 
    ... 
} 

Appで\のHttp \微信依存関係を注入

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; 
} 

.PHPエラー・スタック

  • Container.phpラインでBindingResolutionException 850: 解決できない依存関係の解決[パラメータ#0 [$オプション]]クラスAppで\のHttp \ Container.phpラインで
  • 微信、コンテナで850
  • > 、コンテナ> getDependenciesでContainer.php線817
  • でresolveNonClass(オブジェクト(ReflectionParameter))(配列(オブジェクト(ReflectionParameter))、アレイ())Container.phpライン790
+0

私はあなたがここで '作曲ダンプ-autoload'を実行する必要があると思います –

答えて

1

のステップのすべてされているp erfectly、しかし、あなたはproviders配列の下config/app.phpにもあなたのサービスプロバイダに登録する必要があります

'providers' => [ 
    // .. others 
    WechatServiceProvider::class, 
], 
関連する問題