Skip to content

Commit aa4482f

Browse files
committed
feat: update container internals docs
1 parent efdcbae commit aa4482f

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
---
22
title: The container
3+
description: "Tempest's container has a unique synergy with discovery. Learn how it differs from other frameworks' implementations."
34
---
45

5-
Here's a short summary of how the Tempest container works.
6+
In contrast to other frameworks, Tempest doesn't have a concept of service provider. Instead, the instantiation process of dependencies is specified in [initializer classes](../1-essentials/01-container#dependency-initializers), which are automatically [discovered](./02-discovery).
67

7-
- Tempest doesn't have service providers like Laravel. Instead, it has **initializer** classes. Think of an initializer as a class that knows how to construct an object or interface.
8-
- Tempest will discover these initializer classes for you. You don't need to register them anywhere.
9-
- The container will also **autowire** as much as possible, so you only need initializer classes if you need to do manual setup work
8+
Additionally, the container will also [autowire](../1-essentials/01-container#injecting-dependencies) dependencies as much as possible, so initializer classes may only be used when there is the need for specific, manual set-up code.
109

11-
Here's an example of a very simple initializer class:
10+
The following is an example of an initializer:
1211

13-
```php
12+
```php LoggerInitializer.php
1413
#[Singleton]
1514
final readonly class LoggerInitializer implements Initializer
1615
{
@@ -23,10 +22,6 @@ final readonly class LoggerInitializer implements Initializer
2322
}
2423
```
2524

26-
A couple of things to note about it:
25+
Tempest knows that this initializer produces a `Logger` or `LoggerInterface` thanks to the return type of the `initialize()` method. The first time one of these objects is injected as a dependency, the container will call this initializer class.
2726

28-
- It has the `#[Singleton]` attribute, which means that this dependency will be registered as a **singleton**
29-
- Tempest knows what kind of objects this initializer can create, based on the **return type**. This initializer will be used any time a `LoggerInterface` or `Logger` is requested from the container
30-
- Again, you don't need to register this class anywhere. Tempest will discover it for you automatically
31-
32-
If you want to know more about initializer discovery in particular, you can check out `\Tempest\Container\InitializerDiscovery`
27+
Additionally, thanks to the `#[Singleton]` attribute, the logger instance will be registered as a singleton—which means this initializer will be called only once by the container.

0 commit comments

Comments
 (0)