| 13 | import { IAppContainer } from '../interfaces'; |
| 14 | |
| 15 | export class AppContainer implements IAppContainer { |
| 16 | private app: Express; |
| 17 | controllers: Function[] = []; |
| 18 | baseUri: string = ''; |
| 19 | startMiddleware: Function[] = []; |
| 20 | endMiddleware: Function[] = []; |
| 21 | appStartMiddleware: Function[] = []; |
| 22 | diContainer: any; |
| 23 | diResolveCallback: any; |
| 24 | errorController: Function; |
| 25 | routeNotFoundMiddleware: Function; |
| 26 | errorMiddleware: Function[] = []; |
| 27 | raiseModelError = false; |
| 28 | enableTaskContext = false; |
| 29 | useRouter: IRouterCallBack; |
| 30 | |
| 31 | constructor(app: Express) { |
| 32 | this.app = app; |
| 33 | } |
| 34 | |
| 35 | build(): void { |
| 36 | |
| 37 | let dinoContainer = DinoContainer.create({ |
| 38 | app: this.app, |
| 39 | raiseModelError: this.raiseModelError, |
| 40 | enableTaskContext: this.enableTaskContext, |
| 41 | routerCallback: this.useRouter, |
| 42 | baseUri: this.baseUri, |
| 43 | diContainer: this.diContainer, |
| 44 | diResolveCb: this.diResolveCallback |
| 45 | }); |
| 46 | |
| 47 | // attach dino property to response object on every request start |
| 48 | dinoContainer.builtInRequestStartMiddleware(DinoStartMiddleware); |
| 49 | |
| 50 | if (this.enableTaskContext) { |
| 51 | dinoContainer.builtInRequestStartMiddleware(TaskContextMiddleware); |
| 52 | } |
| 53 | |
| 54 | if (!DataUtility.isUndefinedOrNull(this.routeNotFoundMiddleware)) { |
| 55 | dinoContainer.routeNotFoundMiddleware(this.routeNotFoundMiddleware); |
| 56 | } |
| 57 | |
| 58 | for (const middleware of this.startMiddleware) { |
| 59 | dinoContainer.requestStartMiddleware(middleware); |
| 60 | } |
| 61 | |
| 62 | for (const controller of this.controllers) { |
| 63 | dinoContainer.registerController(controller); |
| 64 | } |
| 65 | |
| 66 | for (const middleware of this.endMiddleware) { |
| 67 | dinoContainer.requestEndMiddleware(middleware); |
| 68 | } |
| 69 | |
| 70 | // Note:- built-in RequestEndMiddleware must be registered |
| 71 | // after registering user requestEndMiddlewares |
| 72 |
nothing calls this directly
no outgoing calls
no test coverage detected