This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ketamine.js
69 lines (49 loc) · 1.74 KB
/
ketamine.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(function (factory) {
if (typeof define === 'function' && define.amd) {
define('ketamine' , ['ketamine/injector', 'ketamine/configurator'], factory.bind(this, this));
} else {
if (typeof require === 'function') {
factory(this, require('./injector'), require('./configurator'));
}
}
})(function (global, Injector, Configurator) {
var Ketamine = function (require, basePath, pathResolver) {
require = require || global.require;
if (!basePath && global.process && typeof global.process.cwd === 'function') {
basePath = global.process.cwd();
}
this.injector = new Injector(require, basePath, pathResolver);
this.basePath = basePath;
};
Ketamine.prototype.configure = function (config) {
if (typeof config === 'function') {
var configurator = new Configurator(this.injector);
config(configurator.configureForModule.bind(configurator));
} else {
this.injector.configure(config);
}
};
Ketamine.prototype.register = function (moduleId, options) {
this.injector.register(moduleId, options);
};
Ketamine.prototype.get = function (moduleId) {
return this.injector.get(moduleId);
};
Ketamine.prototype.require = Ketamine.prototype.get;
Ketamine.prototype.create = function (moduleId) {
return this.injector.get(moduleId, true);
};
Ketamine.prototype.setDependencies = function (moduleId, dependencies) {
return this.injector.setDependencies(moduleId, dependencies);
};
Ketamine.prototype.setInstantiation = function (moduleId, instantiate) {
return this.injector.setInstantiation(moduleId, instantiate);
};
function createKetamine (require, basePath) {
return new Ketamine(require, basePath);
}
if (typeof module !== 'undefined') {
module.exports = createKetamine;
}
return createKetamine;
});