I want all my repositories to be listed in a single service provider, but I don't want them all loaded at once...
Consider the service provider below:
class RepositoryServiceProvider extends ServiceProvider {
protected $defer = true;
public function register()
{
$this->app->bind(
'App\Repositories\Contracts\FooRepository',
'App\Repositories\SQL\FooSQLRepository');
$this->app->bind(
'App\Repositories\Contracts\BarRepository',
'App\Repositories\SQL\BarSQLRepository');
// and more to be added later...
}
public function provides()
{
// Will it defer and load all these at once? Or only the one(s) needed?
return ['App\Repositories\Contracts\FooRepository',
'App\Repositories\Contracts\BarRepository'];
}
}
According to the Laravel docs, I can defer the registration of bindings until needed. But does this work for when I've added multiple bindings in a single service provider? Specifically I mean, will it defer and then load all or load only the one needed?