Elemental lowcode development platform.
The service provider gives you a mechanism to resolve your custom services within a website controller. It has the following methods available:
These methods are covered in more detail below.
Parameters:
name
- string, the name of the service to resolveAttempts to resolve the service named with the name parameter. If the system cannot resolve this, or any dependent services, then an exception will be thrown.
This can be called from your controllers like so:
module.exports = {
events : {
load : (event) => {
const emailService = this.serviceProvider.resolveService("emailService");
return emailService.sendEmail("me@philip-skinner.co.uk", "Hello", "How are you doing today?");
}
}
};
Parameters:
fn
- function, the function to resolve the dependencies forAttempts to resolve the dependencies for the function. If the system cannot resolve all of the dependencies then an exception will be thrown.
This can be called from your controllers like so:
module.exports = {
events : {
load : (event) => {
return this.serviceProvider.resolveRequirements((emailService, templateService) => {
return templateService.renderTemplate("emailTemplate").then((output) => {
return emailService.sendEmail("me@philip-skinner.co.uk", "Hello", output);
});
});
}
}
}