Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <[email protected]>
  • Loading branch information
ghostwriter committed Jul 26, 2023
1 parent 6cc6b00 commit 22e64b7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,38 @@ class TasksServiceProvider implements ServiceProviderInterface
$container->register(TasksServiceProvider::class);
```

### Contextual Bindings

Registering a Contextual Bindings on the container.

```php
interface ClientInterface { }

class RestClient implements ClientInterface {
}

class GraphQLClient implements ClientInterface {
}

final class GitHub
{
public function __construct(
private readonly ClientInterface $client
) {
}
public function getClient(): ClientInterface
{
return $this->client;
}
}

// When GitHub::class asks for ClientInterface::class, it should receive GraphQLClient::class.
$container->provide(GitHub::class, ClientInterface::class, GraphQLClient::class);

// When any service asks for ClientInterface::class, it should receive RestClient::class.
$container->alias(ClientInterface::class, RestClient::class);
```

### Service Extensions

Registering a service extension on the container.
Expand Down

0 comments on commit 22e64b7

Please sign in to comment.