Skip to main content
InterviewHubPRO
Section Overview
Q39

Question 39 of 50

Part 3: Octane, High-Throughput Scaling & Enterprise Design (25 - 35)

78%
Laravel & Ecosystem (50 Qs)•Part 3: Octane, High-Throughput Scaling & Enterprise Design (25 - 35)

The Service Container: Singletons, Scoped, and Contextual Binding.

senior LevelDocker & Containers

In Simple Words: The Laravel Service Container is a dependency injection tool:

  • $this->app->bind(Interface::class, Implementation::class): Creates a new instance on every resolve.
  • $this->app->singleton(...): Resolves once and shares the instance throughout the entire application lifecycle.
  • $this->app->scoped(...): In Laravel Octane, scoped instances live for the duration of a single HTTP request and reset between requests.
  • Contextual Binding: Injects different implementations of the same interface into different classes based on context: $this->app->when(PhotoController::class)->needs(Filesystem::class)->give(S3Filesystem::class);