Service Factory Reference

This section of the documentation provides a reference to the methods generated for services extending the service factory (MedusaService) and how to use them.

Tip: Refer to the Service Factory documentation to learn more.

Method Names#

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 the retrieve operation.

Some examples of method names:

  • createPosts
  • createMyPosts
  • 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 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#

Note: The reference uses only the operation name to refer to the method.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break