Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/guide/concept/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,24 @@ For convenience, there is a naming convention for custom string keys:

### Service providers

As an alternative to registering dependencies directly, you can use service providers. Basically, these are classes that
given parameters are configuring and registering services within the container. Similar to three dependency configuration
files described, there are three configs for specifying service providers: `providers-console.php` for console
commands, `providers-web.php` for web application and `providers.php` for both:
As an alternative to registering dependencies directly, you can use service providers. A service provider is a class
that receives configured options and registers services within the container.

Similar to container configuration files, there are three configs for specifying service providers:
`providers-console.php` for console commands, `providers-web.php` for web application and `providers.php` for both.

Prefer direct container configuration for application services with a simple definition: a class name, an interface
implementation, constructor arguments from `$params`, or a closure that creates a single service.

Use a service provider when the registration itself is a unit of code:

- A package registers several related services, aliases, or decorators.
- A service registration also needs supporting definitions.
- The same registration should be reused in several applications.
- Registration depends on runtime checks, optional classes, or environment-specific decisions.

Use a factory class when construction logic belongs to one service. A factory returns an object. A service provider
registers definitions in the container.

```php
/* @var array $params */
Expand Down
Loading