Skip to content

Commit

Permalink
Adds the scoped instances documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Jun 13, 2021
1 parent 51d5e75 commit e634173
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions container.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ The `singleton` method binds a class or interface into the container that should
return new Transistor($app->make(PodcastParser::class));
});

<a name="binding-scoped"></a>
#### Binding Scoped Instances

The `scoped` method binds a class or interface into the container that should only be resolved one time inside the same context. Differently than the `singleton` method, instances registered with the `scoped` method will be flushed whenever the Laravel Application switches contexts, such as when a Laravel Octane Worker processes a new request or when Laravel Queue Worker processes a new Job:

use App\Services\Transistor;
use App\Services\PodcastParser;

$this->app->scoped(Transistor::class, function ($app) {
return new Transistor($app->make(PodcastParser::class));
});

<a name="binding-instances"></a>
#### Binding Instances

Expand Down

0 comments on commit e634173

Please sign in to comment.