// 一般ユーザー認証サービス
$this->app->when(UserAuthService::class)
->needs(AuthServiceInterface::class)
->give(function () {
return new BasicAuthService();
});
// 管理者認証サービス
$this->app->when(AdminAuthService::class)
->needs(AuthServiceInterface::class)
->give(function () {
return new TwoFactorAuthService();
});AuthServiceInterfaceという同じインターフェースに対して、ユーザー種別に応じて異なる認証サービスを注入しています:UserAuthServiceにはBasicAuthServiceを注入
AdminAuthServiceにはTwoFactorAuthServiceを注入