diff --git a/src/api/api.dependencies.ts b/src/api/api.dependencies.ts index 5615ef5..db32b7d 100644 --- a/src/api/api.dependencies.ts +++ b/src/api/api.dependencies.ts @@ -1,6 +1,7 @@ import { Container, Result, Route, UnknownObject } from '@alien-worlds/api-core'; import { DatabaseConfigBuilder, Dependencies } from '../common'; import { Api } from './api'; +import { ApiConfig } from './api.types'; /** * An abstract class representing a Api dependencies. @@ -9,6 +10,8 @@ import { Api } from './api'; export abstract class ApiDependencies extends Dependencies { public api: Api; public ioc: Container; + public setupIoc: (config: ApiConfig, container: Container) => Promise; + public routesProvider: (container: Container) => Route[]; public databaseConfigBuilder: DatabaseConfigBuilder; public abstract initialize( diff --git a/src/api/start-api.ts b/src/api/start-api.ts index 5465dd1..a4fe4c9 100644 --- a/src/api/start-api.ts +++ b/src/api/start-api.ts @@ -6,15 +6,14 @@ import { ApiCommandOptions } from './api.types'; import { buildApiConfig } from '../config'; import { ApiDependencies } from './api.dependencies'; -export const startApi = async ( - dependencies: ApiDependencies, - routes: Route[] = [], - ...args: string[] -) => { - const { api, databaseConfigBuilder } = dependencies; +export const startApi = async (dependencies: ApiDependencies, ...args: string[]) => { + const { api, ioc, databaseConfigBuilder, routesProvider, setupIoc } = dependencies; const vars = new ConfigVars(); const options = apiCommand.parse(args).opts(); const config = buildApiConfig(vars, databaseConfigBuilder, options); + const routes = routesProvider(ioc); + + await setupIoc(config, ioc); api.setup(config);