Skip to content

[9.x] Allow terser singleton bindings #43469

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

Merged
merged 1 commit into from
Jul 29, 2022
Merged

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);
    }
}

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@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

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
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.

None yet

3 participants