Skip to content

Instantly share code, notes, and snippets.

@crizstian
Created February 1, 2017 19:00
Show Gist options
  • Save crizstian/6f7ead5936e1ca2784c1796c2746d69e to your computer and use it in GitHub Desktop.
Save crizstian/6f7ead5936e1ca2784c1796c2746d69e to your computer and use it in GitHub Desktop.
Example of dependency injection
// more code
mediator.on('db.ready', (db) => {
let rep
// here we are making DI to the repository
// we are injecting the database object and the ObjectID object
repository.connect({
db,
ObjectID: config.ObjectID
})
.then(repo => {
console.log('Connected. Starting Server')
rep = repo
// here we are also making DI to the server
// we are injecting serverSettings and the repo object
return server.start({
port: config.serverSettings.port,
ssl: config.serverSettings.ssl,
repo
})
})
.then(app => {
console.log(`Server started succesfully, running on port: ${config.serverSettings.port}.`)
app.on('close', () => {
rep.disconnect()
})
})
})
// more code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment