c9 / architect

A simple yet powerful plugin system for large-scale node applications
MIT License
982 stars 129 forks source link

How to share the "consumed" services #67

Open HiraveBapu opened 6 years ago

HiraveBapu commented 6 years ago

Lets say i have plugin called "data-distribution" which consumes three services service1, service2,service3. In the "data-distribution" folder / plugin, there are other js files/modules are created. In one of the module of "data-distribution" needs to access "service1", how would it access it ?

so in other words, every single file has to be "plugin" (its own folder with package.json) or can it be some higher level plugin and all other can share the imported services ?

greuze commented 5 years ago

From your data-distribution plugin, you can access the services through imports parameter, and you can store them in a variable in that file (or other), or pass to other classes when requireing them, for example:

module.exports = function setup(options, imports, register) {
    var otherFile = require('./other-file-not-plugin')(imports.service1);

or using something like otherFile.setService(service1), that doesn't need to be a plugin.