How to create custom singleton service and inject to other services? #2406
Answered
by
srindom
eric-makro
asked this question in
Q&A
-
How to create custom singleton service and inject to other services? |
Beta Was this translation helpful? Give feedback.
Answered by
srindom
Oct 19, 2022
Replies: 1 comment 1 reply
-
We have creation of custom services documented here: https://docs.medusajs.com/advanced/backend/services/create-service In your Medusa project you can place a file at This service will automatically be registered in Medusa's dependency container as To use it in other services you would do something like: class SomeService {
// ...
constructor({ coolStuffService }) {
// ...
}
} To use it in an endpoint controller you can do: const coolStuffService = req.scope.resolve("coolStuffService`) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
srindom
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have creation of custom services documented here: https://docs.medusajs.com/advanced/backend/services/create-service
In your Medusa project you can place a file at
/src/services/cool-stuff.js
that default exports a service.This service will automatically be registered in Medusa's dependency container as
coolStuffService
.To use it in other services you would do something like:
To use it in an endpoint controller you can do: