【发布时间】:2016-05-28 03:01:41
【问题描述】:
我使用的是 Laravel-5.0 的默认 Authentication 中间件,但是我将句柄函数的签名更改为:
public function handle($request, Closure $next, AuthClientInterface $authClient)
我还在服务提供商处注册了AuthClientInterface:
public function register()
{
$this->app->bind('App\Services\Contracts\AuthClientInterface', function()
{
return new AuthClient(
env('AUTH_SERVER_URL'),
env('AUTH_SESSION_URL'),
env('AUTH_CLIENT_ID')
);
});
}
但是,尽管如此,我还是看到了以下错误:
Argument 3 passed to HelioQuote\Http\Middleware\Authenticate::handle()
must be an instance of
HelioQuote\Services\Contracts\HelioAuthClientInterface, none given,
called in C:\MyApp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php on line 125 and defined...
谁能看出我做错了什么?
编辑:我确实通过将 HelioAuthClientInterface 传递给中间件的构造函数来使其工作。但是我认为除了构造函数之外,IoC 容器还会将依赖项注入到方法中。
【问题讨论】:
标签: php laravel ioc-container middleware