-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.js
48 lines (26 loc) · 1000 Bytes
/
container.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module.exports = function Container(){
var services = {};
//PRIVATE
function getDeps(deps){ // loop through the deps associated with an implementation and return them in a json to the constructor
var depObjs = {};
var d;
for(var i = 0; i < deps.length; i++){
var dep = deps[i];
d = services[dep].implementation;
depObjs[dep] = new d();
};
return depObjs;
}
//PUBLIC
function registerComponentImp(name, implementation, deps){
services[name] = {implementation:implementation, deps:deps};
}
function getImplementation(name){
var cla = services[name];
return new cla.implementation(getDeps(cla.deps)); // pass dependencies into the implementations constructor
}
return {
registerComponentImp: registerComponentImp,
getImplementation: getImplementation
}
};