Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Created January 30, 2019 12:57
Show Gist options
  • Save hypeJunction/eb81ca513c61e9afae79ecd4a86bf66c to your computer and use it in GitHub Desktop.
Save hypeJunction/eb81ca513c61e9afae79ecd4a86bf66c to your computer and use it in GitHub Desktop.
import Container from '../app/Container';
import Express from 'express';
import { createNamespace } from 'cls-hooked';
import uuid4 from 'uuid/v4';
import EventEmitter from 'events';
import config from '../config';
import Logger from './Logger';
import DatabaseConnection from './DatabaseConnection';
import Database from './Database';
import Signer from './Signer';
import Session from './Session';
import Auth from './Auth';
import MailerTransport from './MailerTransport';
import Mailer from './Mailer';
import Stripe from './Stripe';
import Password from './Password';
export default () => {
const namespace = createNamespace(uuid4());
const container = new Container(namespace);
const express = new Express();
express.use((req, res, next) => {
namespace.bindEmitter(req);
namespace.bindEmitter(res);
namespace.run(() => {
next();
});
});
container.register('config', () => config);
container.register('express', () => express);
container.register('events', EventEmitter);
container.register('session', Session, ['auth', 'db'], { scoped: true });
container.register('logger', Logger, ['config']);
container.register('dbConnection', DatabaseConnection, ['config', 'logger']);
container.register('db', Database, ['dbConnection']);
container.register('signer', Signer, ['config']);
container.register('mailerTransport', MailerTransport, ['config']);
container.register('mailer', Mailer, ['config', 'logger', 'mailerTransport', 'views']);
container.register('auth', Auth, ['config', 'logger', 'db', 'signer']);
container.register('stripe', Stripe, ['config']);
container.register('password', Password);
return container;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment