Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v9] Service providers should all $provide #3

Open
KorvinSzanto opened this issue Dec 17, 2017 · 0 comments
Open

[v9] Service providers should all $provide #3

KorvinSzanto opened this issue Dec 17, 2017 · 0 comments
Labels

Comments

@KorvinSzanto
Copy link
Contributor

KorvinSzanto commented Dec 17, 2017

Service providers already have the ability to declare what it is that they provide via the $provides interface. This makes it so the container can lazy load service providers and only register the ones that are needed as part of a request potentially speeding up $app->make calls and the site significantly.

So what does a service provider look like that provides?

class ServiceProvider extends Provider
{

    public $provides = [
        Foo::class,
        Bar::class,
        FooBar::class
    ];

    public function register()
    {
        $this->app->bind(Foo::class, function() {
            return new Foo();
        });
        $this->app->bind(Bar::class, function() {
            return new Bar();
        });
        $this->app->bind(FooBar::class, function() {
            return new FooBar();
        });
    }

}

That's all. Now we can cache a lookup table and only register providers that need to be registered.

Considerations

  • Many providers are registered without the use of a "registerer" class
    IE: (new CustomServiceProvider($app))->register()
    These will just work as they do today. Instead we should have a simple way to push providers onto the container, maybe something like $app->provide($provider)
  • This may add cache level considerations
  • Performance is the key benefactor, this must be profiled thoroughly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant