Skip to content

Commit 7426fca

Browse files
committed
feat: convert singleton manager to lazy ghost
This allows the manager to be dependency injected without loading the entities until they are actually needed.
1 parent 06bb814 commit 7426fca

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/ServiceProvider.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Support\Collection;
1212
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
1313
use Override;
14+
use ReflectionClass;
1415
use Symfony\Component\Finder\Finder;
1516

1617
class ServiceProvider extends IlluminateServiceProvider implements DeferrableProvider
@@ -26,7 +27,11 @@ public function provides(): array
2627
public function register(): void
2728
{
2829
$this->app->singleton(SqlEntityManager::class, function (Application $app) {
29-
return new SqlEntityManager($this->getEntities($app), $app->make('db'));
30+
return (new ReflectionClass(SqlEntityManager::class))
31+
->newLazyGhost(fn ($m) => $m->__construct(
32+
$this->getEntities($app),
33+
$app->make('db'),
34+
));
3035
});
3136

3237
$this->app->alias(SqlEntityManager::class, 'sql-entities');

0 commit comments

Comments
 (0)