Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 744 Bytes

service-providers.md

File metadata and controls

28 lines (24 loc) · 744 Bytes
title description
Service Providers
The `app/Providers` folder

Service Providers

The app/Providers folder should contain Service Providers files. The usage of Laravel Service Providers is the best way to specify when a concrete implementation is bound to a contract/interface:

public function register()
{
    $this->app->singleton(Contract::class, function ($app) {
        return new Concrete(config('database'));
    });
}

app(Contract::class) // Returns a Concrete implementation.

This is useful, because you may want to ask for the contract instead of the implementation:

public function handle(ServiceContract $service): void
{
    $service->execute('foo');
}