- modules can be also nested appolo apps with own
contextthey function as independent appolo app.
- module can also export instances that will be injected to main app injector.
- modules can load own nested modules.
- each module instance is uniq you can load the same module multiple time with different options.
- modules can be loaded in sequence or in parallel mode.
module env will be merged with module parent env.
each module must inherit from
now load module in main app modules
now load modules in parallel
now monitoring controller is part of our app the route
/api/monitor in available
module options can be injected in any module class
some time you need to load a module before the main app is loaded for example the logger module
module can use all
appolo features like async factories.
the app will be launched when all modules finished loading
we load the module in the main app and define the id of db client.
now you can inject the db instance anywhere in the main app
beforeAppInitialize- called on App initialize
beforeModuleInitialize- called before module initialize
beforeModuleLaunch- called before module launch
onInjectInitialize- called on module init method
onInjectBootstrap- called on module bootstrap method
afterModuleInitialize- called after module initialized and inject finish loading
afterModuleLaunch- called after module launched finish the bootstrap process
afterAppInitialize- called after app initialized and inject finish loading
afterAppLaunch- called after app launch finish the bootstrap process
beforeReset- called before app reset
reset- called before app reset
The module instance can be used with inject only after the
Inner modules can inject instances from parent App or modules loaded on the parent App.
it will look the logger instance first in the module injector if not found it will look in the module parent injector util it will reach the root injector if the instance not found error will be thrown
moduleOptions - return module options
parent- return module parent app
app- return module app
rootParent- return top root app
moduleOptions- return custom module config
defaults- return default custom module config
Third party modules can be easily loaded into appolo inject and used in inject container.
Each module must call
app.module.loadFn before it can be used by appolo launcher.
app.module.loadFn accepts a function as an argument.
The last argument to that function must be the
next function, modules loaded serially, so each module must call the next function or return a promise in order to continue the launch process.
Other arguments to the function are object which you wish to inject into the module (these objects must be injected earlier).
By default, each module can inject:
- env - environment object
- inject - injector - to add objects to the injector
- app - the app instance
- or any previous loaded module instances
Now we can inject myModuleObject to any class
module can loaded in parallel
A logger module example with winston
Now we you inject logger anywhere we need it