UNPKG

1.05 kBPlain TextView Raw
1import * as DI from './di'
2import {repositoryMap} from '../core/exports'
3import {ClassType} from '../core/utils/classtype';
4
5let repoSource = function (target: ClassType<any>) {
6 let repo;
7 if (!target) {
8 return null;
9 }
10 Object.keys(repositoryMap())
11 .forEach(x => {
12 //// TODO: Decide repository map will hold the prototype or the function
13 var path;
14 if (target.prototype) {
15 path = target.prototype.path;
16 }
17 else if (target['default']) {
18 path = target['default'].prototype.path;
19 }
20 if (path === x) {
21 repo = repositoryMap()[x].repo;
22 }
23 //if (repositoryMap()[x].fn === target || <Function>repositoryMap()[x].fn === target.prototype|| (target.prototype && x === target.prototype.path)) {
24 // repo = repositoryMap()[x].repo;
25 //}
26 });
27 return repo;
28}
29
30DI.Container.addSource(repoSource);
31
32export let Container: DI.IContainer = DI.Container;