Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.register({
app: asClass(Application).singleton(),
server: asClass(Server).singleton()
})
.register({
router: asFunction(router).singleton(),
logger: asFunction(logger).singleton()
})
.register({
config: asValue(config)
});
// Middlewares
container
.register({
loggerMiddleware: asFunction(loggerMiddleware).singleton()
})
.register({
containerMiddleware: asValue(scopePerRequest(container)),
errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
swaggerMiddleware: asValue([swaggerMiddleware])
});
// Repositories
container.register({
usersRepository: asClass(SequelizeUsersRepository).singleton()
});
// Database
container.register({
database: asValue(database),
UserModel: asValue(UserModel)
const database = require('./infra/mongoose');
const container = createContainer();
container.register({
// System
app: asClass(Application, { lifetime: Lifetime.SINGLETON }),
server: asClass(Server, { lifetime: Lifetime.SINGLETON }),
router: asFunction(router, { lifetime: Lifetime.SINGLETON }),
logger: asFunction(logger, { lifetime: Lifetime.SINGLETON }),
config: asValue(config),
//Middlewares
loggerMiddleware: asFunction(loggerMiddleware, { lifetime: Lifetime.SINGLETON }),
containerMiddleware: asValue(scopePerRequest(container)),
errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
swaggerMiddleware: asValue(swaggerMiddleware),
//Repositories
usersRepository: asClass(MongoUsersRepository, { lifetime: Lifetime.SINGLETON }),
//Database
database: asFunction(database),
UserModel: asValue(UserModel),
//Operations
createUser: asClass(CreateUser),
getAllUsers: asClass(GetAllUsers),
updateUser: asClass(UpdateUser),
const router = require('./interfaces/http/router')
const auth = require('./interfaces/http/auth')
const config = require('../config')
const logger = require('./infra/logging/logger')
const database = require('./infra/database')
const jwt = require('./infra/jwt')
const response = require('./infra/support/response')
const date = require('./infra/support/date')
const repository = require('./infra/repositories')
const container = createContainer()
// SYSTEM
container
.register({
app: asFunction(app).singleton(),
server: asFunction(server).singleton(),
router: asFunction(router).singleton(),
logger: asFunction(logger).singleton(),
database: asFunction(database).singleton(),
auth: asFunction(auth).singleton(),
jwt: asFunction(jwt).singleton(),
response: asFunction(response).singleton(),
date: asFunction(date).singleton(),
config: asValue(config),
repository: asFunction(repository).singleton()
})
module.exports = container
const swaggerMiddleware = require('./interfaces/http/swagger/swaggerMiddleware');
const logger = require('./infra/logging/logger');
const SequelizeUsersRepository = require('./infra/user/SequelizeUsersRepository');
const { database, User: UserModel } = require('./infra/database/models');
const container = createContainer();
// System
container
.register({
app: asClass(Application).singleton(),
server: asClass(Server).singleton()
})
.register({
router: asFunction(router).singleton(),
logger: asFunction(logger).singleton()
})
.register({
config: asValue(config)
});
// Middlewares
container
.register({
loggerMiddleware: asFunction(loggerMiddleware).singleton()
})
.register({
containerMiddleware: asValue(scopePerRequest(container)),
errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
swaggerMiddleware: asValue([swaggerMiddleware])
});
const logger = require('./infra/logging/logger');
const SequelizeUsersRepository = require('./infra/user/SequelizeUsersRepository');
const { database, User: UserModel } = require('./infra/database/models');
const container = createContainer();
// System
container
.register({
app: asClass(Application).singleton(),
server: asClass(Server).singleton()
})
.register({
router: asFunction(router).singleton(),
logger: asFunction(logger).singleton()
})
.register({
config: asValue(config)
});
// Middlewares
container
.register({
loggerMiddleware: asFunction(loggerMiddleware).singleton()
})
.register({
containerMiddleware: asValue(scopePerRequest(container)),
errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
swaggerMiddleware: asValue([swaggerMiddleware])
});
const database = require('./infra/database')
const jwt = require('./infra/jwt')
const response = require('./infra/support/response')
const date = require('./infra/support/date')
const repository = require('./infra/repositories')
const container = createContainer()
// SYSTEM
container
.register({
app: asFunction(app).singleton(),
server: asFunction(server).singleton(),
router: asFunction(router).singleton(),
logger: asFunction(logger).singleton(),
database: asFunction(database).singleton(),
auth: asFunction(auth).singleton(),
jwt: asFunction(jwt).singleton(),
response: asFunction(response).singleton(),
date: asFunction(date).singleton(),
config: asValue(config),
repository: asFunction(repository).singleton()
})
module.exports = container
logger: asFunction(logger, { lifetime: Lifetime.SINGLETON }),
config: asValue(config),
//Middlewares
loggerMiddleware: asFunction(loggerMiddleware, { lifetime: Lifetime.SINGLETON }),
containerMiddleware: asValue(scopePerRequest(container)),
errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
swaggerMiddleware: asValue(swaggerMiddleware),
//Repositories
usersRepository: asClass(MongoUsersRepository, { lifetime: Lifetime.SINGLETON }),
//Database
database: asFunction(database),
UserModel: asValue(UserModel),
//Operations
createUser: asClass(CreateUser),
getAllUsers: asClass(GetAllUsers),
updateUser: asClass(UpdateUser),
getUserByUid: asClass(GetByUid),
deleteUser: asClass(DeleteUser),
//Serializer
userSerializer: asValue(UserSerializer)
});
module.exports = container;
function getResolver (options: InjectableTableEntry) {
const provider = options.provider
if (provider.useConstructor) {
return asClass(provider.useConstructor, options)
} else if (provider.useValue) {
return asValue(provider.useValue)
} else if (provider.useFactory) {
return asFunction(provider.useFactory)
} else {
throw new Error('useConstructor, useValue, or useFactory must be specified')
}
}