我想创建一个包含命令的软件包。给定命令依赖于对依赖库的绑定-这样:
"extra": {
"laravel": {
"providers": [
"Test\\ServiceProvider"
]
}
}
<?php
namespace Test;
use Illuminate\Support\ServiceProvider as Provider;
use Test\Commands\TestCommand;
use External\Package\Binding;
class ServiceProvider extends Provider
{
public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([
TestCommand::class,
]);
}
}
public function register()
{
$this->app->singleton(Binding::class, function () {
return new Binding();
});
}
}
<?php
namespace Test\Commands;
use Illuminate\Console\Command;
use External\Package\Binding;
class TestCommand extends Command
{
public function __construct(Binding $binding)
{
parent::__construct();
$this->binding = $binding;
}
}
但是我得到了
Illuminate \ Contracts \ Container \ BindingResolutionException:构建[Test \ Commands \ TestCommand]时无法实例化目标[External \ Package \ Binding]
如何解决这个问题?