master
 1import * as commands from '../services/commands';
 2import * as queries from '../services/queries';
 3import Api from '../infrastructure/api';
 4import ApplicationStorage from '../infrastructure/application-storage';
 5import Configuration from '../infrastructure/configuration';
 6import EventAggregator from '../infrastructure/event-aggregator';
 7import Registry from '../infrastructure/registry';
 8import Router from '../infrastructure/router'
 9
10export default class WireUpComponentsInto {
11  constructor(registry = new Registry()) {
12    this.registry = registry;
13  }
14
15  run() {
16    this.registry.register('eventAggregator', EventAggregator).asSingleton();
17    this.registry.register('router', (container) => {
18      return new Router({
19        eventAggregator: container.resolve('eventAggregator'),
20        registry: this.registry
21      });
22    }).asSingleton();
23    this.registry.register('applicationStorage', ApplicationStorage).asSingleton();
24    const overrides = { 
25      API_HOST: 'http://localhost:3000',
26      ENV: 'development',
27      LOCAL_ONLY: 'true',
28    };
29    this.registry.register('configuration', (container) => new Configuration(overrides)).asSingleton();
30    this.registry.register('api', Api).asSingleton();
31
32    this.registerSubscribers(commands);
33    this.registerSubscribers(queries);
34
35    this.registry.resolveAll("subscriber").forEach((subscriber) => {
36      subscriber.subscribeTo(this.registry.resolve('eventAggregator'));
37    });
38    return this.registry;
39  }
40
41  registerSubscribers(subscribers) {
42    for (let subscriber in subscribers) {
43      this.registry.register('subscriber', subscribers[subscriber]).asSingleton();
44    }
45  }
46}