Use Config/Services.php to register and retrieve shared singleton service instances.
Services and Libraries
// app/Config/Services.php — register custom services
class Services extends BaseService {
public static function paymentGateway(bool $getShared = true): PaymentGateway {
if ($getShared) return static::getSharedInstance("paymentGateway");
return new StripeGateway(
config("Payment")->apiKey,
config("Payment")->secretKey
);
}
}
// Use anywhere
$gateway = ConfigServices::paymentGateway();
// Built-in services
$email = ConfigServices::email();
$validator = ConfigServices::validation();
$request = ConfigServices::request();
$response = ConfigServices::response();
$uri = ConfigServices::uri();
$logger = ConfigServices::logger();