chores(medusa): cleanup registrations life time (#3699)

This commit is contained in:
Adrien de Peretti
2023-04-05 12:15:44 +02:00
committed by GitHub
parent 4c268238a4
commit 914d57336b
6 changed files with 28 additions and 23 deletions
@@ -153,7 +153,7 @@ Notice that you have to wrap your usage of the new resource in a try-catch block
If you want to access new registrations in the dependency container within a service, you must set the lifetime of the service either to `Lifetime.SCOPED` or `Lifetime.TRANSIENT`. Services that have a `Lifetime.SINGLETON` lifetime can't access new registrations since they're resolved and cached in the root dependency container beforehand. You can learn more in the [Create Services documentation](../services/create-service.md#service-life-time).
For custom services, no additional action is required as the default lifetime is `Lifetime.TRANSIENT`. However, if you extend a core service, you must change the lifetime since the default lifetime for core services is `Lifetime.SINGLETON`.
For custom services, no additional action is required as the default lifetime is `Lifetime.SCOPED`. However, if you extend a core service, you must change the lifetime since the default lifetime for core services is `Lifetime.SINGLETON`.
For example:
@@ -110,7 +110,7 @@ Each service is registered under its camel-case name. For example, the `ProductS
</td>
<td>
Core services by default have the `SINGLETON` lifetime. However, some have a different lifetime which is indicated in this table. Custom services, including services in plugins, by default have the `TRANSIENT` lifetime, unless defined differently within the custom service.
Core services by default have the `SINGLETON` lifetime. However, some have a different lifetime which is indicated in this table. Custom services, including services in plugins, by default have the `SCOPED` lifetime, unless defined differently within the custom service.
</td>
</tr>
@@ -182,7 +182,7 @@ Every payment processor is registered under two names:
</td>
<td>
By default, it's `TRANSIENT` unless defined differently within the payment processor service.
By default, it's `SINGLETON` unless defined differently within the payment processor service.
</td>
</tr>
@@ -205,7 +205,7 @@ An array of all payment processor that extend the `AbstractPaymentService` or `A
</td>
<td>
`paymentProviders` is `TRANSIENT`, and each item in it is `TRANSIENT`.
`paymentProviders` is `TRANSIENT`, and each item in it is `SINGLETON`.
</td>
</tr>
@@ -254,7 +254,7 @@ An array of all fulfillment providers that extend the `FulfillmentService` class
</td>
<td>
`fulfillmentProviders` is `TRANSIENT`, and each item in it is `TRANSIENT`.
`fulfillmentProviders` is `TRANSIENT`, and each item in it is `SINGLETON`.
</td>
</tr>
@@ -303,7 +303,7 @@ An array of all notification providers that extend the `AbstractNotificationServ
</td>
<td>
`notificationProviders` is `TRANSIENT`, and each item in it is `TRANSIENT`.
`notificationProviders` is `TRANSIENT`, and each item in it is `SINGLETON`.
</td>
</tr>
@@ -329,7 +329,7 @@ The file service is registered under two names:
</td>
<td>
By default, it's `TRANSIENT` unless defined differently within the file service.
By default, it's `SINGLETON` unless defined differently within the file service.
</td>
</tr>
@@ -355,7 +355,7 @@ The search service is registered under two names:
</td>
<td>
By default, it's `TRANSIENT` unless defined differently within the search service.
By default, it's `SINGLETON` unless defined differently within the search service.
</td>
</tr>
@@ -404,7 +404,7 @@ An array of every tax provider that extends the `AbstractTaxService` class.
</td>
<td>
`taxProviders` is `TRANSIENT`, and each item in it is `TRANSIENT`.
`taxProviders` is `TRANSIENT`, and each item in it is `SINGLETON`.
</td>
</tr>
@@ -427,7 +427,7 @@ Each Oauth Service is registered under its camel-case name followed by `Oauth`.
</td>
<td>
By default, it's `TRANSIENT` unless defined differently within the Oauth service.
By default, it's `SINGLETON` unless defined differently within the Oauth service.
</td>
</tr>
@@ -38,8 +38,8 @@ As the dependency container in Medusa is built on top of [awilix](https://github
There are three lifetime types:
1. `Lifetime.TRANSIENT`: (default for custom services) when used, a new instance of the service is created everytime it is resolved in other resources from the dependency container.
2. `Lifetime.SCOPED`: when used, an instance of the service is created and reused in the scope of the dependency container. So, when the service is resolved in other resources that share that dependency container, the same instance of the service will be returned.
1. `Lifetime.TRANSIENT`: when used, a new instance of the service is created everytime it is resolved in other resources from the dependency container.
2. `Lifetime.SCOPED`: (default for custom services) when used, an instance of the service is created and reused in the scope of the dependency container. So, when the service is resolved in other resources that share that dependency container, the same instance of the service will be returned.
3. `Lifetime.SINGLETON`: (default for core services) when used, the service is always reused, regardless of the scope. An instance of the service is cached in the root container.
You can set the lifetime of your service by setting the `LIFE_TIME` static property: