Closed BAN1ce closed 6 years ago
+1
No support for deferred service providers in Lumen.
What you can do though, is something similar to what Lumen does with its register...Bindings()
methods. You can have your own registering function and a corresponding $availableBindings
record. You of course need to extend original Laravel\Lumen\Application
class to make this happen. I do this personally and it works great.
What Lumen really needs, is a way to register these lazy bindings without extending original Application
. Something like $app->lazyBinding[$abstract] = $closure
, granted that it still performs better than $app->bind($abstract, $closure)
, otherwise it would be a futile exercise.
No support for deferred service providers in Lumen.
What you can do though, is something similar to what Lumen does with its
register...Bindings()
methods. You can have your own registering function and a corresponding$availableBindings
record. You of course need to extend originalLaravel\Lumen\Application
class to make this happen. I do this personally and it works great.What Lumen really needs, is a way to register these lazy bindings without extending original
Application
. Something like$app->lazyBinding[$abstract] = $closure
, granted that it still performs better than$app->bind($abstract, $closure)
, otherwise it would be a futile exercise.
Hi,
You have an example of your code for this implemention ? thanks
Extend Lumen application:
<?php
namespace Acme\Support;
use Illuminate\Support\Arr;
use Laravel\Lumen\Application as LumenApplication;
class Application extends LumenApplication
{
/**
* Register bindings for MyService.
*/
protected function registerMyServiceBindings()
{
$this->configure('myservice');
$this->register('Acme\Providers\MyServiceProvider');
}
/**
* { inherit_doc }.
*/
protected function registerCacheBindings()
{
// parent::registerCacheBindings();
// Modify original Lumen cache bindings here to suit my application.
}
}
And then in your "bootstrap/app.php":
$app = new Acme\Support\Application(
realpath(__DIR__.'/../')
);
$app->availableBindings[\Acme\Contracts\MyService::class] = 'registerMyServiceBindings';
So when doing:
$app->make(\Acme\Contracts\MyService::class)
it will run Acme\Support\Application::registerMyServiceBindings()
first and then return whatever you have configured in your service provider.
Notice how you can override original Lumen bindings too.
Heya, Lumen indeed doesn't allow deferring of service providers at this time.
Description:
I want create a defer service provider , according to laravel doc create a provider which not defer.I found lumen function
registerDeferredProvider
is weird.this function content only one line codereturn $this->register($provider);
.So,No defer ?Steps To Reproduce: