app->bind(GameBoardState::class, function ($app) { $width = (int) config('app.game.board.width', 4); $height = (int) config('app.game.board.height', 4); return new GameBoardState($width, $height); }); $this->app->singleton(GameService::class, function ($app) { // Try loading from session. $session_key = config('app.game.session_name', 'game.service'); $service = Session::get($session_key); // No service in session, create a new one and store it. if (!$service) { $game_session = $app->make(GameSession::class); $service = new GameService($game_session); Session::put($session_key, $service); } return $service; }); $this->app->alias(GameService::class, 'game'); } /** * Get the services provided by the provider. * * @return array */ public function provides() { return ['game', GameService::class, GameBoardState::class]; } }