【发布时间】:2015-07-08 01:00:15
【问题描述】:
我希望我的所有存储库都列在一个服务提供商中,但我不希望它们一次全部加载...
考虑下面的服务提供商:
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,我可以将绑定的注册推迟到需要时。但是,当我在单个服务提供者中添加多个绑定时,这是否有效?具体来说,我的意思是,它会延迟然后加载all还是只加载需要的一个?
【问题讨论】:
标签: php laravel laravel-5 service-provider deferred-loading