docs: add documentation for v1.8 (#3669)

This commit is contained in:
Shahed Nasser
2023-04-03 13:50:59 +02:00
committed by GitHub
parent 0cca13779d
commit c6bfad14d8
123 changed files with 7610 additions and 2697 deletions
@@ -2,9 +2,9 @@
description: 'Learn what the dependency container is and how to use it in Medusa. Learn also what dependency injection is, and what the resources regsitered and their names are.'
---
# Dependency Injection
# Dependency Container and Injection
In this document, youll learn what the dependency injection is and how you can use it in Medusa.
In this document, youll learn what the dependency container is and how you can use it in Medusa with dependency injection.
## Introduction
@@ -36,13 +36,13 @@ The backend then registers all important resources in the container, which makes
The Medusa backend scans the core Medusa package, plugins, and your files in the `dist` directory and registers the following resources:
:::note
:::tip
Many resources are registered under their camel-case name. These resources are formatted by taking the name of the file, transforming it to camel case, then appending the folder name to the name. So, the `services/product.ts` service is registered as `productService`.
The Lifetime column indicates the lifetime of a service. Other resources that aren't services don't have a lifetime, which is indicated with the `-` in the column. You can learn about what a lifetime is in the [Create a Service](../services/create-service.md) documentation.
:::
<table class="reference-table">
<table class="reference-table table-col-4">
<thead>
<tr>
<th>
@@ -60,6 +60,11 @@ Description
Registration Name
</th>
<th>
Lifetime
</th>
</tr>
</thead>
@@ -79,6 +84,11 @@ The configurations that are exported from `medusa-config.js`.
`configModule`
</td>
<td>
\-
</td>
</tr>
@@ -97,6 +107,11 @@ Services that extend the `TransactionBaseService` class.
Each service is registered under its camel-case name. For example, the `ProductService` is registered as `productService`.
</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.
</td>
</tr>
@@ -115,6 +130,11 @@ An instance of Typeorms Entity Manager.
`manager`
</td>
<td>
\-
</td>
</tr>
@@ -133,45 +153,60 @@ An instance of Medusa CLIs logger. You can use it to log messages to the term
`logger`
</td>
<td>
\-
</td>
</tr>
<tr>
<td>
Single Payment Provider
Single Payment Processor
</td>
<td>
An instance of every payment provider that extends the `AbstractPaymentService` class.
An instance of every payment processor that extends the `AbstractPaymentService` or the `AbstractPaymentProcessor` classes.
</td>
<td>
Every payment provider is registered under two names:
Every payment processor is registered under two names:
- Its camel-case name. For example, the `StripeProviderService` is registered as `stripeProviderService`.
- Its camel-case name of the processor. For example, the `StripeProviderService` is registered as `stripeProviderService`.
- `pp_` followed by its identifier. For example, the `StripeProviderService` is registered as `pp_stripe`.
</td>
<td>
By default, it's `TRANSIENT` unless defined differently within the payment processor service.
</td>
</tr>
<tr>
<td>
All Payment Providers
All Payment Processors
</td>
<td>
An array of all payment providers that extend the `AbstractPaymentService` class.
An array of all payment processor that extend the `AbstractPaymentService` or `AbstractPaymentProcessor` class.
</td>
<td>
`paymentProviders`
</td>
<td>
`paymentProviders` is `TRANSIENT`, and each item in it is `TRANSIENT`.
</td>
</tr>
@@ -193,6 +228,11 @@ Every fulfillment provider is registered under two names:
- Its camel-case name. For example, the `WebshipperFulfillmentService` is registered as `webshipperFulfillmentService`.
- `fp_` followed by its identifier. For example, the `WebshipperFulfillmentService` is registered as `fp_webshipper`.
</td>
<td>
By default, it's `SINGLETON` unless defined differently within the fulfillemnt provider service.
</td>
</tr>
@@ -211,6 +251,11 @@ An array of all fulfillment providers that extend the `FulfillmentService` class
`fulfillmentProviders`
</td>
<td>
`fulfillmentProviders` is `TRANSIENT`, and each item in it is `TRANSIENT`.
</td>
</tr>
@@ -232,6 +277,11 @@ Every notification provider is registered under two names:
- Its camel-case name. For example, the `SendGridService` is registered as `sendGridService`.
- `noti_` followed by its identifier. For example, the `SendGridService` is registered as `noti_sendgrid`.
</td>
<td>
By default, it's `SINGLETON` unless defined differently within the notification provider service.
</td>
</tr>
@@ -250,6 +300,11 @@ An array of all notification providers that extend the `AbstractNotificationServ
`notificationProviders`
</td>
<td>
`notificationProviders` is `TRANSIENT`, and each item in it is `TRANSIENT`.
</td>
</tr>
@@ -271,6 +326,11 @@ The file service is registered under two names:
- Its camel-case name. For example, the `MinioService` is registered as `minioService`.
- `fileService`
</td>
<td>
By default, it's `TRANSIENT` unless defined differently within the file service.
</td>
</tr>
@@ -292,6 +352,11 @@ The search service is registered under two names:
- Its camel-case name. For example, the `AlgoliaService` is registered as `algoliaService`.
- `searchService`
</td>
<td>
By default, it's `TRANSIENT` unless defined differently within the search service.
</td>
</tr>
@@ -313,6 +378,11 @@ The tax provider is registered under two names:
- Its camel-case name.
- `tp_` followed by its identifier.
</td>
<td>
By default, it's `SINGLETON` unless defined differently within the tax provider service.
</td>
</tr>
@@ -331,6 +401,11 @@ An array of every tax provider that extends the `AbstractTaxService` class.
`taxProviders`
</td>
<td>
`taxProviders` is `TRANSIENT`, and each item in it is `TRANSIENT`.
</td>
</tr>
@@ -349,6 +424,11 @@ An instance of every service that extends the `OauthService` class.
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.
</td>
</tr>
@@ -367,6 +447,11 @@ An instance of the `FlagRouter`. This can be used to list feature flags, set a f
`featureFlagRouter`
</td>
<td>
\-
</td>
</tr>
@@ -385,6 +470,11 @@ An instance of the Redis client. If Redis is not configured, a fake Redis client
`redisClient`
</td>
<td>
\-
</td>
</tr>
@@ -403,6 +493,11 @@ An instance of every entity.
Each entity is registered under its camel-case name followed by Model. For example, the `CustomerGroup` entity is stored under `customerGroupModel`.
</td>
<td>
\-
</td>
</tr>
@@ -421,6 +516,11 @@ An array of all database entities that is passed to Typeorm when connecting to t
`db_entities`
</td>
<td>
\-
</td>
</tr>
@@ -439,6 +539,11 @@ An instance of each repository.
Each repository is registered under its camel-case name. For example, `CustomerGroupRepository` is stored under `customerGroupRepository`.
</td>
<td>
\-
</td>
</tr>
@@ -461,6 +566,11 @@ Each batch job strategy is registered under three names:
- `batch_` followed by its identifier. For example, the `ProductImportStrategy` is registered under `batch_product-import-strategy`.
- `batchType_` followed by its batch job type. For example, the `ProductImportStrategy` is registered under `batchType_product-import`.
</td>
<td>
\-
</td>
</tr>
@@ -479,6 +589,11 @@ An array of all classes extending the `AbstractBatchJobStrategy` abstract class.
`batchJobStrategies`
</td>
<td>
\-
</td>
</tr>
@@ -497,6 +612,11 @@ An instance of the class implementing the `ITaxCalculationStrategy` interface.
`taxCalculationStrategy`
</td>
<td>
\-
</td>
</tr>
@@ -515,6 +635,11 @@ An instance of the class extending the `AbstractCartCompletionStrategy` class.
`cartCompletionStrategy`
</td>
<td>
\-
</td>
</tr>
@@ -533,6 +658,11 @@ An instance of the class implementing the `IPriceSelectionStrategy` interface.
`priceSelectionStrategy`
</td>
<td>
\-
</td>
</tr>
@@ -551,6 +681,11 @@ An instance of strategies that arent of the specific types mentioned above an
Its camel-case name.
</td>
<td>
\-
</td>
</tr>
</tbody>
@@ -576,7 +711,7 @@ Please note that in endpoints some resources, such as repositories, are not avai
### In Classes
In classes such as services, strategies, or subscribers, you can load resources in the constructor function. The constructor receives an object of dependencies as a first parameter. Each dependency in the object should use the registration name of the resource that should be injected to the class.
In classes such as services, strategies, or subscribers, you can load resources in the constructor function using dependency injection. The constructor receives an object of dependencies as a first parameter. Each dependency in the object should use the registration name of the resource that should be injected to the class.
For example: