- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Menu
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
2.2. Medusa container
In this chapter, you’ll learn about the Medusa container and how to use it.
What is the Medusa container?#
The Medusa container holds all resources registered in the Medusa application, such as services.
In your customizations, you use the Medusa container to resolve these resources and use their functionalities.
For example, in a custom API route you can resolve any service registered in the Medusa application using the scope.resolve
method of the MedusaRequest
parameter:
1import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"2import { IProductModuleService } from "@medusajs/framework/types"3import { Modules } from "@medusajs/framework/utils"4 5export const GET = async (6 req: MedusaRequest, 7 res: MedusaResponse8) => {9 const productModuleService: IProductModuleService = req.scope.resolve(10 Modules.PRODUCT11 )12 13 const [, count] = await productModuleService14 .listAndCountProducts()15 16 res.json({17 count,18 })19}
Was this chapter helpful?