Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function configureContainer() {
const opts = {
injectionMode: InjectionMode.CLASSIC
}
return createContainer(opts)
// load modules and registers 加载,注册模块 e.g. import userService from `services/user-service.js`
.loadModules(modulesToLoad, {
cwd: `${__dirname}/..`,
formatName: 'camelCase'
})
.register({
// construct logger
logger: asValue(logger)
})
}
export function configureContainer() {
const opts = {
// Classic means Awilix will look at function parameter
// names rather than passing a Proxy.
injectionMode: InjectionMode.CLASSIC
}
return createContainer(opts)
.loadModules(modulesToLoad, {
// `modulesToLoad` paths should be relative
// to this file's parent directory.
cwd: `${__dirname}/..`,
// Example: registers `services/todo-service.js` as `todoService`
formatName: 'camelCase'
})
.register({
// Our logger is already constructed,
// so provide it as-is to anyone who wants it.
logger: asValue(logger)
})
}
export async function startCli() {
try {
// Awilix is a dependency injection container.
const container = createContainer({
injectionMode: InjectionMode.CLASSIC
}).register({
typeDefinitionSource: asFunction(createTypeDefinitionSource).singleton(),
packageJSONService: asFunction(createPackageJSONFileService).singleton(),
packageSource: asFunction(createPackageSource).singleton(),
globber: asFunction(createGlobber).singleton(),
typeSyncer: asFunction(createTypeSyncer)
})
await run(container.resolve('typeSyncer'))
} catch (err) {
C.error(err)
process.exitCode = 1
}
}
private registerModule(
globPattern,
formatName?
): void {
this.container.loadModules(globPattern, {
formatName: formatName || 'camelCase',
cwd: '.',
resolverOptions: {
injectionMode: InjectionMode.CLASSIC,
lifetime: Lifetime.SINGLETON
}
});
}