blob: a11eeff2dbc9ecce60181025df781c2772cd610a (
plain)
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
|
import * as commands from '../services/commands';
import * as queries from '../services/queries';
import Api from '../infrastructure/api';
import ApplicationStorage from '../infrastructure/application-storage';
import Configuration from '../infrastructure/configuration';
import EventAggregator from '../infrastructure/event-aggregator';
import Registry from '../infrastructure/registry';
import Router from '../infrastructure/router'
export default class WireUpComponentsInto {
constructor(registry = new Registry()) {
this.registry = registry;
}
run() {
this.registry.register('eventAggregator', EventAggregator).asSingleton();
this.registry.register('router', (container) => {
return new Router({
eventAggregator: container.resolve('eventAggregator')
});
}).asSingleton();
this.registry.register('applicationStorage', ApplicationStorage).asSingleton();
this.registry.register('configuration', Configuration).asSingleton();
this.registry.register('api', Api).asSingleton();
this.registerSubscribers(commands);
this.registerSubscribers(queries);
this.registry.resolveAll("subscriber").forEach((subscriber) => {
subscriber.subscribeTo(this.registry.resolve('eventAggregator'));
});
return this.registry;
}
registerSubscribers(subscribers) {
for (let subscriber in subscribers) {
console.log(`registering: ${subscriber}`);
this.registry.register('subscriber', subscribers[subscriber]).asSingleton();
}
}
}
|