Skip to content

Conversation

@timacdonald
Copy link
Member

@timacdonald timacdonald commented Jul 29, 2022

It is currently possible to bind singletons to a service provider using the following:

class AppServiceProvider
{
    public $singletons = [
        Abstract::class => Concrete::class,
    ];
}

Often I want to bind a singleton to the container that isn't backed by contract:

class AppServiceProvider
{
    public $singletons = [
        Concrete::class => Concrete::class,
    ];
}

This always trips me up, as I first try:

class AppServiceProvider
{
    public $singletons = [
        Concrete::class,
    ];
}

This PR makes that work. I expect that to work as it is possible within the register function, thus this also creates symmetry between the two methods of registering singletons:

class AppServiceProvider
{
    public function register()
    {
        $this->app->singleton(Concrete::class);
    }
}

@timacdonald timacdonald changed the title [9.x] Allow simpler singleton binding syntax [9.x] Allow terser singleton bindings Jul 29, 2022
@timacdonald timacdonald marked this pull request as ready for review July 29, 2022 06:56
@taylorotwell taylorotwell merged commit 83c425b into laravel:9.x Jul 29, 2022
@timacdonald timacdonald deleted the singleton branch August 7, 2022 23:57
Ken-vdE pushed a commit to Ken-vdE/framework that referenced this pull request Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants