Skip to content

Commit 48aafd6

Browse files
Add Boost guidelines for Octane dependency injection (#1099)
* Add Boost guidelines for Octane dependency injection * Update core.blade.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent f90d794 commit 48aafd6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Octane
2+
3+
- Octane boots the application once and reuses it across requests, so singletons persist between requests.
4+
- The Laravel container's `scoped` method may be used as a safe alternative to `singleton`.
5+
- Never inject the container, request, or config repository into a singleton's constructor; use a resolver closure or `bind()` instead:
6+
7+
```php
8+
// Bad
9+
$this->app->singleton(Service::class, fn (Application $app) => new Service($app['request']));
10+
11+
// Good
12+
$this->app->singleton(Service::class, fn () => new Service(fn () => request()));
13+
```
14+
15+
- Never append to static properties, as they accumulate in memory across requests.

0 commit comments

Comments
 (0)