@@ -16,6 +16,9 @@ import { events, EventEmitter } from './api/events';
1616import { Log } from './log' ;
1717
1818
19+ import { User } from '../api/models/User' ;
20+
21+
1922class IoC {
2023
2124 public container : Container ;
@@ -34,15 +37,16 @@ class IoC {
3437 }
3538
3639 public async bindModules ( ) : Promise < void > {
37- // this.bindCore();
38- // this.bindModels();
40+ this . bindCore ( ) ;
41+ await this . bindModels ( ) ;
3942 // this.bindControllers();
4043
4144 this . container = this . customConfiguration ( this . container ) ;
4245 }
4346
4447 private bindCore ( ) : void {
4548 this . container . bind < typeof Log > ( Types . Core ) . toConstantValue ( Log ) . whenTargetNamed ( Core . Log ) ;
49+ this . container . bind < EventEmitter > ( Types . Core ) . toConstantValue ( events ) . whenTargetNamed ( Core . Events ) ;
4650 }
4751
4852 private async bindControllers ( ) : Promise < void > {
@@ -59,18 +63,22 @@ class IoC {
5963 } ) ;
6064 }
6165
62- private bindModels ( ) : void {
63- console . log ( 'Models' ) ;
64- this . getFiles ( '/models' , ( files : string [ ] ) => {
65- files . forEach ( ( file : any ) => {
66- const fileExport = require ( `${ file . path } /${ file . fileName } ` ) ;
67- this . validateExport ( fileExport [ file . name ] ) ;
68- this . validateTarget ( Model , file . name ) ;
69- console . log ( Model [ file . name ] ) ;
70- this . container
71- . bind < any > ( Types . Model )
72- . to ( fileExport [ file . name ] )
73- . whenTargetNamed ( Model [ file . name ] ) ;
66+ private bindModels ( ) : Promise < void > {
67+ return new Promise < void > ( ( resolve , reject ) => {
68+ console . log ( 'Models' ) ;
69+ this . getFiles ( '/models' , ( files : string [ ] ) => {
70+ files . forEach ( ( file : any ) => {
71+ const fileExport = require ( `${ file . path } /${ file . fileName } ` ) ;
72+ this . validateExport ( fileExport [ file . name ] ) ;
73+ this . validateTarget ( Model , file . name ) ;
74+
75+ this . container
76+ . bind < any > ( Types . Model )
77+ . toConstantValue ( fileExport [ file . name ] )
78+ . whenTargetNamed ( Model [ file . name ] ) ;
79+
80+ resolve ( ) ;
81+ } ) ;
7482 } ) ;
7583 } ) ;
7684 }
0 commit comments