You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Tempest's container has a unique synergy with discovery. Learn how it differs from other frameworks' implementations."
3
4
---
4
5
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).
6
7
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.
10
9
11
-
Here's an example of a very simple initializer class:
10
+
The following is an example of an initializer:
12
11
13
-
```php
12
+
```php LoggerInitializer.php
14
13
#[Singleton]
15
14
final readonly class LoggerInitializer implements Initializer
16
15
{
@@ -23,10 +22,6 @@ final readonly class LoggerInitializer implements Initializer
23
22
}
24
23
```
25
24
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.
27
26
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