docs: added a section on loader execution (#12260)

This commit is contained in:
Shahed Nasser
2025-04-22 18:56:01 +03:00
committed by GitHub
parent 71a9a7210c
commit 567d7607cd
3 changed files with 16407 additions and 16387 deletions

View File

@@ -100,6 +100,16 @@ This indicates that the loader in the `hello` module ran and logged this message
---
## When are Loaders Executed?
When you start the Medusa application, it executes the loaders of all modules in their registration order.
A loader is executed before the module's main service is instantiated. So, you can use loaders to register in the module's container resources that you want to use in the module's service. For example, you can register a database connection.
Loaders are also useful to only load a module if a certain condition is met. For example, if you try to connect to a database in a loader but the connection fails, you can throw an error in the loader to prevent the module from being loaded. This is useful if your module depends on an external service to work.
---
## Example: Register Custom MongoDB Connection
As mentioned in this chapter's introduction, loaders are most useful when you need to register a custom resource in the module's container to re-use it in other customizations in the module.

View File

@@ -19,7 +19,7 @@ export const generatedEditDates = {
"app/learn/fundamentals/events-and-subscribers/page.mdx": "2025-04-18T10:42:32.803Z",
"app/learn/fundamentals/modules/container/page.mdx": "2025-03-18T15:10:03.574Z",
"app/learn/fundamentals/workflows/execute-another-workflow/page.mdx": "2024-12-09T15:56:22.895Z",
"app/learn/fundamentals/modules/loaders/page.mdx": "2025-03-24T06:40:39.948Z",
"app/learn/fundamentals/modules/loaders/page.mdx": "2025-04-22T15:32:00.430Z",
"app/learn/fundamentals/admin/widgets/page.mdx": "2024-12-09T16:43:24.260Z",
"app/learn/fundamentals/data-models/page.mdx": "2025-03-18T07:55:56.252Z",
"app/learn/fundamentals/modules/remote-link/page.mdx": "2024-09-30T08:43:53.127Z",

File diff suppressed because it is too large Load Diff