Created
February 2, 2017 17:17
-
-
Save hskrasek/1df02cc40149d73b298d3ab9048f37d7 to your computer and use it in GitHub Desktop.
Loading deferred service providers with a non-deferred service provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'providers' => [ | |
'App\Modules\Foo\FooModuleServiceProvider' | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Modules\Foo\Providers; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider { | |
protected $defer = true; | |
public function register() { | |
$this->app->bind(FooThingInterface::class, FooThing::class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Modules\Foo; | |
use Illuminate\Support\ServiceProvider; | |
class FooModuleServiceProvider extends ServiceProvider { | |
protected $defer = false; | |
public function register() { | |
$this->app->register('App\Modules\Foo\Providers\RouteServiceProvider'); // Not deferred since routes are always needed | |
$this->app->register('App\Modules\Foo\Providers\AppServiceProvider'); // Deferred since you don't need all these bindings until you need them | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem with this setup is that
Illuminate\Support\ServiceProvider::isDeferred
is only checked when building the manifest file inIlluminate\Foundation\ProviderRepository
, so registering a deferred service provider anywhere else but theapp.providers
array just loads it normally.