docs: update list of resources in module containers + conventions on loaders (#13107)

This commit is contained in:
Shahed Nasser
2025-07-31 18:14:39 +03:00
committed by GitHub
parent fcb8036412
commit 7bf8ecc013
8 changed files with 373 additions and 81 deletions
@@ -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 CLIs 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 CLIs 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
+2 -2
View File
@@ -106,7 +106,7 @@ export const generatedEditDates = {
"app/deployment/page.mdx": "2025-06-24T08:50:10.114Z",
"app/integrations/page.mdx": "2025-06-25T10:48:35.928Z",
"app/medusa-cli/page.mdx": "2024-08-28T11:25:32.382Z",
"app/medusa-container-resources/page.mdx": "2025-04-17T08:48:10.255Z",
"app/medusa-container-resources/page.mdx": "2025-07-31T13:24:15.786Z",
"app/medusa-workflows-reference/page.mdx": "2025-01-20T08:21:29.962Z",
"app/nextjs-starter/page.mdx": "2025-02-26T11:37:47.137Z",
"app/recipes/b2b/page.mdx": "2025-05-20T07:51:40.718Z",
@@ -133,7 +133,7 @@ export const generatedEditDates = {
"app/service-factory-reference/methods/soft-delete/page.mdx": "2024-07-31T17:01:33+03:00",
"app/service-factory-reference/methods/update/page.mdx": "2025-07-31T08:24:03.685Z",
"app/service-factory-reference/tips/filtering/page.mdx": "2025-04-23T14:38:29.068Z",
"app/service-factory-reference/page.mdx": "2024-07-26T14:40:56+00:00",
"app/service-factory-reference/page.mdx": "2025-07-31T13:29:12.136Z",
"app/storefront-development/cart/context/page.mdx": "2025-03-27T14:47:14.258Z",
"app/storefront-development/cart/create/page.mdx": "2025-03-27T14:46:51.473Z",
"app/storefront-development/cart/manage-items/page.mdx": "2025-03-26T15:54:31.446Z",