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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381 | 1
1
38
1
1
1
10
12
10
10
1
1
1
1
1
1
38
38
38
38
1
1
10
5
1
13
13
20
1
59
59
59
60
1
58
58
4
54
53
53
9
44
1
1
2
2
2
1
85
1
1
99
99
4
95
95
9
86
86
31
55
1
54
54
54
1
1
1
1
1
1
1
2
1
8
8
2
6
1
4
4
4
4
4
1
75
75
75
42
75
1
85
85
8
77
77
76
76
77
1
75
75
66
66
75
1
66
66
42
36
6
42
24
24
24
1
1
| System.register(['core-js', 'aurelia-metadata', 'aurelia-logging', './metadata'], function (_export) {
'use strict';
var core, Metadata, AggregateError, Resolver, ClassActivator, emptyParameters, Container;
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
// Fix Function#name on browsers that do not support it (IE):
function test() {}
return {
setters: [function (_coreJs) {
core = _coreJs['default'];
}, function (_aureliaMetadata) {
Metadata = _aureliaMetadata.Metadata;
}, function (_aureliaLogging) {
AggregateError = _aureliaLogging.AggregateError;
}, function (_metadata) {
Resolver = _metadata.Resolver;
ClassActivator = _metadata.ClassActivator;
}],
execute: function () {
Metadata.registration = 'aurelia:registration';
Metadata.instanceActivator = 'aurelia:instance-activator';Iif (!test.name) {
Object.defineProperty(Function.prototype, 'name', {
get: function get() {
var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
// For better performance only parse once, and then cache the
// result through a new accessor for repeated access.
Object.defineProperty(this, 'name', { value: name });
return name;
}
});
}
emptyParameters = Object.freeze([]);
_export('emptyParameters', emptyParameters);
/**
* A lightweight, extensible dependency injection container.
*
* @class Container
* @constructor
*/
Container = (function () {
function Container(constructionInfo) {
_classCallCheck(this, Container);
this.constructionInfo = constructionInfo || new Map();
this.entries = new Map();
this.root = this;
}
/**
* Adds an additional location to search for constructor parameter type info.
*
* @method addParameterInfoLocator
* @param {Function} locator Configures a locator function to use when searching for parameter info. It should return undefined if no parameter info is found.
*/
Container.prototype.addParameterInfoLocator = function addParameterInfoLocator(locator) {
if (this.locateParameterInfoElsewhere === undefined) {
this.locateParameterInfoElsewhere = locator;
return;
}
var original = this.locateParameterInfoElsewhere;
this.locateParameterInfoElsewhere = function (fn) {
return original(fn) || locator(fn);
};
};
/**
* Registers an existing object instance with the container.
*
* @method registerInstance
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Object} instance The instance that will be resolved when the key is matched.
*/
Container.prototype.registerInstance = function registerInstance(key, instance) {
this.registerHandler(key, function (x) {
return instance;
});
};
/**
* Registers a type (constructor function) such that the container returns a new instance for each request.
*
* @method registerTransient
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Function} [fn] The constructor function to use when the dependency needs to be instantiated.
*/
Container.prototype.registerTransient = function registerTransient(key, fn) {
fn = fn || key;
this.registerHandler(key, function (x) {
return x.invoke(fn);
});
};
/**
* Registers a type (constructor function) such that the container always returns the same instance for each request.
*
* @method registerSingleton
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Function} [fn] The constructor function to use when the dependency needs to be instantiated.
*/
Container.prototype.registerSingleton = function registerSingleton(key, fn) {
var singleton = null;
fn = fn || key;
this.registerHandler(key, function (x) {
return singleton || (singleton = x.invoke(fn));
});
};
/**
* Registers a type (constructor function) by inspecting its registration annotations. If none are found, then the default singleton registration is used.
*
* @method autoRegister
* @param {Function} fn The constructor function to use when the dependency needs to be instantiated.
* @param {Object} [key] The key that identifies the dependency at resolution time; usually a constructor function.
*/
Container.prototype.autoRegister = function autoRegister(fn, key) {
var registration;
if (fn === null || fn === undefined) {
throw new Error('fn cannot be null or undefined.');
}
if (typeof fn === 'function') {
registration = Metadata.get(Metadata.registration, fn);
if (registration !== undefined) {
registration.register(this, key || fn, fn);
} else {
this.registerSingleton(key || fn, fn);
}
} else {
this.registerInstance(fn, fn);
}
};
/**
* Registers an array of types (constructor functions) by inspecting their registration annotations. If none are found, then the default singleton registration is used.
*
* @method autoRegisterAll
* @param {Function[]} fns The constructor function to use when the dependency needs to be instantiated.
*/
Container.prototype.autoRegisterAll = function autoRegisterAll(fns) {
var i = fns.length;
while (i--) {
this.autoRegister(fns[i]);
}
};
/**
* Registers a custom resolution function such that the container calls this function for each request to obtain the instance.
*
* @method registerHandler
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Function} handler The resolution function to use when the dependency is needed. It will be passed one arguement, the container instance that is invoking it.
*/
Container.prototype.registerHandler = function registerHandler(key, handler) {
this.getOrCreateEntry(key).push(handler);
};
/**
* Unregisters based on key.
*
* @method unregister
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
*/
Container.prototype.unregister = function unregister(key) {
this.entries['delete'](key);
};
/**
* Resolves a single instance based on the provided key.
*
* @method get
* @param {Object} key The key that identifies the object to resolve.
* @return {Object} Returns the resolved instance.
*/
Container.prototype.get = function get(key) {
var entry;
if (key === null || key === undefined) {
throw new Error('key cannot be null or undefined.');
}
Iif (key === Container) {
return this;
}
if (key instanceof Resolver) {
return key.get(this);
}
entry = this.entries.get(key);
if (entry !== undefined) {
return entry[0](this);
}
if (this.parent) {
return this.parent.get(key);
}
this.autoRegister(key);
entry = this.entries.get(key);
return entry[0](this);
};
/**
* Resolves all instance registered under the provided key.
*
* @method getAll
* @param {Object} key The key that identifies the objects to resolve.
* @return {Object[]} Returns an array of the resolved instances.
*/
Container.prototype.getAll = function getAll(key) {
var _this = this;
var entry;
Iif (key === null || key === undefined) {
throw new Error('key cannot be null or undefined.');
}
entry = this.entries.get(key);
Eif (entry !== undefined) {
return entry.map(function (x) {
return x(_this);
});
}
if (this.parent) {
return this.parent.getAll(key);
}
return [];
};
/**
* Inspects the container to determine if a particular key has been registred.
*
* @method hasHandler
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Boolean} [checkParent=false] Indicates whether or not to check the parent container hierarchy.
* @return {Boolean} Returns true if the key has been registred; false otherwise.
*/
Container.prototype.hasHandler = function hasHandler(key) {
var checkParent = arguments[1] === undefined ? false : arguments[1];
if (key === null || key === undefined) {
throw new Error('key cannot be null or undefined.');
}
return this.entries.has(key) || checkParent && this.parent && this.parent.hasHandler(key, checkParent);
};
/**
* Creates a new dependency injection container whose parent is the current container.
*
* @method createChild
* @return {Container} Returns a new container instance parented to this.
*/
Container.prototype.createChild = function createChild() {
var childContainer = new Container(this.constructionInfo);
childContainer.parent = this;
childContainer.root = this.root;
childContainer.locateParameterInfoElsewhere = this.locateParameterInfoElsewhere;
return childContainer;
};
/**
* Invokes a function, recursively resolving its dependencies.
*
* @method invoke
* @param {Function} fn The function to invoke with the auto-resolved dependencies.
* @return {Object} Returns the instance resulting from calling the function.
*/
Container.prototype.invoke = function invoke(fn) {
try {
var info = this.getOrCreateConstructionInfo(fn),
keys = info.keys,
args = new Array(keys.length),
i,
ii;
for (i = 0, ii = keys.length; i < ii; ++i) {
args[i] = this.get(keys[i]);
}
return info.activator.invoke(fn, args);
} catch (e) {
var activatingText = info.activator instanceof ClassActivator ? 'instantiating' : 'invoking';
var message = 'Error ' + activatingText + ' ' + fn.name + '.';
if (i < ii) {
message += ' The argument at index ' + i + ' (key:' + keys[i] + ') could not be satisfied.';
}
message += ' Check the inner error for details.';
throw AggregateError(message, e, true);
}
};
Container.prototype.getOrCreateEntry = function getOrCreateEntry(key) {
var entry;
if (key === null || key === undefined) {
throw new Error('key cannot be null or undefined.');
}
entry = this.entries.get(key);
if (entry === undefined) {
entry = [];
this.entries.set(key, entry);
}
return entry;
};
Container.prototype.getOrCreateConstructionInfo = function getOrCreateConstructionInfo(fn) {
var info = this.constructionInfo.get(fn);
if (info === undefined) {
info = this.createConstructionInfo(fn);
this.constructionInfo.set(fn, info);
}
return info;
};
Container.prototype.createConstructionInfo = function createConstructionInfo(fn) {
var info = { activator: Metadata.getOwn(Metadata.instanceActivator, fn) || ClassActivator.instance };
if (fn.inject !== undefined) {
if (typeof fn.inject === 'function') {
info.keys = fn.inject();
} else {
info.keys = fn.inject;
}
return info;
}
Iif (this.locateParameterInfoElsewhere !== undefined) {
info.keys = this.locateParameterInfoElsewhere(fn) || Reflect.getOwnMetadata(Metadata.paramTypes, fn) || emptyParameters;
} else {
info.keys = Reflect.getOwnMetadata(Metadata.paramTypes, fn) || emptyParameters;
}
return info;
};
return Container;
})();
_export('Container', Container);
}
};
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9FaXNlbmJlcmdFZmZlY3QvRG9jdW1lbnRzL0dpdEh1Yi9UaGUgRHVyYW5kYWwgUH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