You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: container.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,6 +178,22 @@ $this->app->singletonIf(Transistor::class, function (Application $app) {
178
178
});
179
179
```
180
180
181
+
Alternatively, you may mark an interface or class with the `#[Singleton]` attribute to indicate to the container that it should be resolved one time:
182
+
183
+
```php
184
+
<?php
185
+
186
+
namespace App\Services;
187
+
188
+
use Illuminate\Container\Attributes\Singleton;
189
+
190
+
#[Singleton]
191
+
class Transistor
192
+
{
193
+
// ...
194
+
}
195
+
```
196
+
181
197
<aname="binding-scoped"></a>
182
198
#### Binding Scoped Singletons
183
199
@@ -201,6 +217,22 @@ $this->app->scopedIf(Transistor::class, function (Application $app) {
201
217
});
202
218
```
203
219
220
+
Alternatively, you may mark an interface or class with the `#[Scoped]` attribute to indicate to the container that it should be resolved one time within a given Laravel request / job lifecycle:
0 commit comments