Multitenant configuration data for the SDK Library

喜欢而已 提交于 2019-12-12 03:48:45

问题


This question builds on an answer to a previous question, where I was looking for a solution to share configuration data between actors (nodejs modules) of a system (SDK) without using Factory pattern.

This time I need to make the SDK multi-tenant by providing different configuration data for distinct SDK instances.

app.js

var SDKAcctA = require("./sdk");
SDKAcctA.config = {key: "key", secret: "secret"};

var SDKAcctB = require("./sdk");
SDKAcctB.config = {key: "key2", secret: "secret2"};

// use both of them concurrently without each one overriding the config data of the other

var mA = new SDKAcctA.M1();
mA.doSomething();

var mB = new SDKAcctB.M1();
mB.doSomething();

sdk.js

var SDK = function(){};

SDK.config = {key: null, secret: null};

module.exports = SDK;

require("./m1"); //executing other modules to make it work

m1.js

var SDK = require("./sdk");

var M1 = function(){};

M1.prototype.doSomething = function(){
    var config = SDK.config //getting access to main module's config data
};

SDK.M1 = M1;

Question:

Right now the configuration data is getting overriden by the other instance and that's what the issue is. Please advise.

来源:https://stackoverflow.com/questions/39111923/multitenant-configuration-data-for-the-sdk-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!