Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
fac/domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Lugavere authored and Ben Lugavere committed Oct 8, 2017
1 parent fddd2d4 commit b5ee20b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
const types = {
db: null,
CatRepository: null,
CatFactory: null,
cats: null,
CatCtrl: null,
CatService: null
CatService: null,
Cat: null
};

for (const i in types) {
if (types[i] === null) {
types[i] = i;
types[i] = i;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as express from 'express';
import { Routes } from './routes/routes';
import { Injector } from 'boxed-injector';
import * as helmet from 'helmet';
import mongo from './config/mongo';
Expand All @@ -20,7 +19,6 @@ export class Server {
// Creates an express aplication, and imports our routes.
// We keep the routes separate to make the code easer to comprehend.
this._app = app;
this._app.use(Routes);

const injector = new Injector();

Expand Down
6 changes: 6 additions & 0 deletions src/services/cats/Cat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

class Cat {

}

export default Cat;
20 changes: 20 additions & 0 deletions src/services/cats/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


import types from '../../config/types';
import * as autoBind from 'auto-bind';
import Cat from './Cat';

class CatFactory {
static inject: Array<string> = [];

constructor() {
autoBind(this);
}

reconstitute(data: any): Promise<Cat> {
return Promise.resolve(new Cat());
}

}

export default CatFactory;
5 changes: 5 additions & 0 deletions src/services/cats/injector.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import types from '../../config/types';
import repository from './repository';
import service from './service';
import ctrl from './ctrl';
import Cat from './Cat';
import CatFactory from './factory';

export default (injector: Injector) => {
const db = injector.get(types.db);
injector.factory(types.CatCtrl, ctrl);
injector.factory(types.CatService, service);
injector.factory(types.CatRepository, repository);
injector.factory(types.CatFactory, CatFactory);
injector.register(types.Cat, Cat);

injector.register(types.cats, db.collection('cats'));
};

0 comments on commit b5ee20b

Please sign in to comment.