Mantra how-to guide

How to instantiate Mantra API object

In some cases, is needed to instantiate a new Mantra API object

14-Apr-2022
A  A  A 

Mantra has been designed to develop high performance applications; the core of the system is an object named Mantra which have all properties and methods needed for the components to interact with the framework and the rest of the application.

This is, Mantra API object is somehow the glue between the framework and all components that constitute an application.

Components get functionality, call others components APIs, access data repositories and the like... using this Mantra API object.

Because of this, this object is heavy to create, and this is the reason why in each Mantra interaction (http requests, DAL operations, events processing, etc.), the framework expects to use just one (and the same) instance of Mantra API object.

However, there's some situations where you need to create the instance of this object manually, like when processing cron jobs and the function handler is called.

To create a new Mantra API instance just use global object:

const Mantra = global.Mantra.MantraAPIFactory();

Mantra expects you to do this just in the situations where the framework cannot instantiate the object for you.

You may be also interested