* docs: changes based on DX changes * remove fields no longer needed * remove unnecessary parameters * fixes to authenticate middleware usage * add highlight to migrations config * change configuration to http * added missing remote link docs * fix name in sidebar * added notification module docs + updated file module docs * add vale exceptions * fix vale errors * added docs on custom cli scripts
74 lines
1.9 KiB
Plaintext
74 lines
1.9 KiB
Plaintext
export const metadata = {
|
|
title: `${pageNumber} Module's Container`,
|
|
}
|
|
|
|
# {metadata.title}
|
|
|
|
In this chapter, you'll learn about the module's container and how to register resources in that container.
|
|
|
|
## Module's Container
|
|
|
|
Each module has a local container only used by the resources of that module.
|
|
|
|
So, resources in the module, such as services or loaders, can only resolve other resources registered in the module's container.
|
|
|
|
---
|
|
|
|
## Resources Registered in the Module's Container
|
|
|
|
Some resources registered in the module's container are:
|
|
|
|
- The module's main service.
|
|
- A generated service for each data model in your module. The registration name is the camel-case data model name suffixed by `Service`. For example, `myCustomService`.
|
|
|
|

|
|
|
|
---
|
|
|
|
## Resolve Resources
|
|
|
|
### Services
|
|
|
|
A service's constructor accepts as a first parameter an object used to resolve resources registered in the module's container.
|
|
|
|
For example:
|
|
|
|
```ts highlights={[["5"], ["12"]]}
|
|
import { ModulesSdkTypes } from "@medusajs/types"
|
|
import { MyCustom } from "./models/my-custom"
|
|
|
|
type InjectedDependencies = {
|
|
myCustomService: ModulesSdkTypes.InternalModuleService<any>
|
|
}
|
|
|
|
export default class HelloModuleService {
|
|
protected myCustomService_:
|
|
ModulesSdkTypes.InternalModuleService<MyCustom>
|
|
constructor({ myCustomService }: InjectedDependencies) {
|
|
this.myCustomService_ = myCustomService
|
|
}
|
|
|
|
// ...
|
|
}
|
|
```
|
|
|
|
### Loader
|
|
|
|
A loader function in a module accepts as a parameter an object having the property `container`. Its value is the module's container used to resolve resources.
|
|
|
|
For example:
|
|
|
|
```ts highlights={[["8"]]}
|
|
import {
|
|
LoaderOptions,
|
|
} from "@medusajs/modules-sdk"
|
|
|
|
export default function helloWorldLoader({
|
|
container,
|
|
}: LoaderOptions) {
|
|
const myCustomService = container.resolve("myCustomService")
|
|
|
|
// ...
|
|
}
|
|
```
|