docs: update list of resources in module containers + conventions on loaders (#13107)
This commit is contained in:
1 parent
fcb8036412
commit
7bf8ecc013
8 files changed
+373
-81
No files matched your search
@@ -6,21 +6,21 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
This documentation page includes the list of resources registered in the container of the Medusa application and modules.
|
||||
This reference provides the list of resources registered in the Medusa container and module containers.
|
||||
|
||||
## Medusa Container Resources
|
||||
|
||||
The following table has a list of all resources that you can resolve in your customizations outside a module (such as API routes or workflows).
|
||||
The following table lists all resources that you can resolve in your customizations outside a module (such as API routes, workflows, subscribers, and scheduled jobs).
|
||||
|
||||
<Note>
|
||||
|
||||
Learn more about the Medusa Container in [this documentation](!docs!/learn/fundamentals/medusa-container).
|
||||
Refer to the [Medusa Container](!docs!/learn/fundamentals/medusa-container) documentation for more information on how to use these resources.
|
||||
|
||||
</Note>
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/utils` where specified.
|
||||
You can use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/utils` where specified.
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -49,12 +49,12 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
|
||||
Configurations
|
||||
[Medusa Configurations](!docs!/learn/configurations/medusa-config)
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
The configurations that are exported from `medusa-config.ts`.
|
||||
The configurations defined in `medusa-config.ts`.
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
@@ -67,12 +67,12 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
|
||||
Logger
|
||||
[Logger](!docs!/learn/debugging-and-testing/logging)
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
An instance of Medusa CLI’s logger. You can use it to log messages to the terminal.
|
||||
Utility to log messages to the terminal.
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
@@ -108,7 +108,7 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
Link function to manage links between records of two modules' data models.
|
||||
Manage links between records of two modules' data models.
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
@@ -131,8 +131,8 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
- For custom modules, the registration name is the key of the module in the `modules` configuration in `medusa-config.ts`.
|
||||
- For Medusa's Commerce Modules, use the `Modules` enum imported from `@medusajs/framework/utils`.
|
||||
- For custom modules, the registration name is the first parameter of `Module` exported in the `index.ts` file of the module.
|
||||
- For Medusa's Commerce and Infrastructural Modules, use the `Modules` enum imported from `@medusajs/framework/utils`.
|
||||
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
@@ -143,17 +143,17 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
|
||||
## Module Container Resources
|
||||
|
||||
The following table has a list of all resources that you can resolve in a module's services or loaders.
|
||||
The following table lists all resources that you can resolve in a module's services or loaders.
|
||||
|
||||
<Note>
|
||||
|
||||
Learn more about the Module Container in [this documentation](!docs!/learn/fundamentals/modules/container).
|
||||
Refer to the [Module Container](!docs!/learn/fundamentals/modules/container) documentation for more information on how to use these resources.
|
||||
|
||||
</Note>
|
||||
|
||||
<Note>
|
||||
|
||||
Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/utils` where specified.
|
||||
Use the `ContainerRegistrationKeys` and `Modules` enums imported from `@medusajs/framework/utils` where specified.
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -182,12 +182,12 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
|
||||
Logger
|
||||
[Logger](!docs!/learn/debugging-and-testing/logging)
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
An instance of Medusa CLI’s logger. You can use it to log messages to the terminal.
|
||||
Utility to log messages to the terminal.
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
@@ -218,12 +218,12 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
|
||||
Base Repository
|
||||
[Base Repository](!docs!/learn/fundamentals/modules/db-operations#configure-transactions-with-the-base-repository)
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
An instance of the base repository, used to run transactions or perform other database operations.
|
||||
An instance of the base repository, used to run transactions and perform database operations.
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
@@ -236,12 +236,12 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
|
||||
Configurations
|
||||
[Medusa Configurations](!docs!/learn/configurations/medusa-config)
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
The configurations exported from `medusa-config.ts`.
|
||||
The configurations defined in `medusa-config.ts`.
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
@@ -254,19 +254,61 @@ Use the `ContainerRegistrationKeys` enum imported from `@medusajs/framework/util
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
|
||||
Modules' services
|
||||
[Event Module](../infrastructure-modules/event/page.mdx)'s service
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
All services exported by the `services/index.ts` file of a module.
|
||||
The service of the Event Module, used to emit events.
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
Each service is registered by its camel-case name. For example, if the service's class name is `ClientService`, its registration name is `clientService`.
|
||||
`event_bus` or `Modules.EVENT_MODULE`
|
||||
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
|
||||
Services generated by the [service factory](../service-factory-reference/page.mdx)
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
The service of every data model passed to the `MedusaService` function that your module's service extends. The service has the methods described in the [service factory reference](../service-factory-reference/page.mdx).
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
Each service is registered as the camel-cased name of the data model. For example:
|
||||
|
||||
- `Brand` data model's service is registered as `brandService`.
|
||||
- `DigitalProduct` data model's service is registered as `digitalProductService`.
|
||||
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
|
||||
Module services
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
You can resolve the module's services from one another, but not in loaders. Learn more in the [Module Container](!docs!/learn/fundamentals/modules/container) documentation.
|
||||
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
|
||||
Each service is registered as the camel-cased name of the service. For example:
|
||||
|
||||
- `BrandModuleService` is registered as `brandModuleService`.
|
||||
- `CmsService` is registered as `cmsService`.
|
||||
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
</Table.Body>
|
||||
</Table>
|
||||
</Table>
|
||||
@@ -6,20 +6,27 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
This section of the documentation provides a reference of the methods generated for services extending the service factory (`MedusaService`), and how to use them.
|
||||
This section of the documentation provides a reference to the methods generated for services extending the service factory (`MedusaService`) and how to use them.
|
||||
|
||||
<Note title="Tip">
|
||||
|
||||
Learn more about the service factory in [this documentation](!docs!/learn/fundamentals/modules/service-factory).
|
||||
Refer to the [Service Factory](!docs!/learn/fundamentals/modules/service-factory) documentation to learn more.
|
||||
|
||||
</Note>
|
||||
|
||||
## Method Names
|
||||
|
||||
Generated method names are of the format `{operationName}_{dataModelName}`, where:
|
||||
When your module's main service extends the service factory, Medusa will:
|
||||
|
||||
1. Generate data-management methods in your main service for each of the data models passed to the `MedusaService` function.
|
||||
2. Generate internal services for each of the data models passed to the `MedusaService` function, which can be resolved in loaders.
|
||||
|
||||
### Main Service Methods
|
||||
|
||||
The names of the generated methods for a service extending the service factory are of the format `{operationName}_{dataModelName}`, where:
|
||||
|
||||
- `{operationName}` is the name of the operation. For example, `create`.
|
||||
- `{dataModelName}` is the pascal-case version of the data model's key that's passed in the object parameter of `MedusaService`. The name is pluralized for all operations except for the `retrieve` operation.
|
||||
- `{dataModelName}` is the pascal-case version of the data model's key that's passed in the object parameter of `MedusaService`. The name is pluralized for all operations except the `retrieve` operation.
|
||||
|
||||
Some examples of method names:
|
||||
|
||||
@@ -28,6 +35,14 @@ Some examples of method names:
|
||||
- `retrievePost`
|
||||
- `listPosts`
|
||||
|
||||
### Internal Generated Service Methods
|
||||
|
||||
The internal services are useful when you need to perform database operations in loaders, as they're executed before the module's services are registered. Learn more in the [Module Container](!docs!/learn/fundamentals/modules/container) documentation.
|
||||
|
||||
For the internal services, the method names are only the operation name, without the data model name.
|
||||
|
||||
For example, a `Post` data model would have a `postService` with methods like `create`, `retrieve`, `update`, and `delete`.
|
||||
|
||||
---
|
||||
|
||||
## Methods Reference
|
||||
|
||||
Reference in new issue
Block a user