使用ServiceProvider后,Laravel给我一个错误500 ... 如果我删除:
我知道,不需要约束,因为没有DI,我正在经历......
GameController:
namespace App\Http\Controllers\Game;
use App;
use App\Http\Controllers\Controller;
class GameController extends Controller
{
public function start(GameRepositoryInterface $gameRepository) {
return $gameRepository->getLastAdd();
}
}
GameServiceProvider:
namespace App\Providers\Game;
use Illuminate\Support\ServiceProvider;
use App\Http\Controllers\Game\StdGameRepository;
use App\Http\Controllers\Game\GameRepositoryInterface;
class GameServiceProvider extends ServiceProvider
{
protected $defer = true;
public function register() {
dd('ici');
$this->app->bind(StdGameRepository::class, function() {
return new StdGameRepository();
});
$this->app->bind(GameRepositoryInterface::class, StdGameRepository::class);
}
public function provides() {
return [GameRepositoryInterface::class];
}
}
GameRepositoryInterface:
namespace App\Http\Controllers\Game;
interface GameRepositoryInterface
{
public function getLastAdd();
}
StdGameRepository:
namespace App\Http\Controllers\Game;
class StdGameRepository implements GameRepositoryInterface
{
private $lastAdd = "Testing";
public function getLastAdd()
{
return $this->lastAdd;
}
}