Created
February 1, 2017 19:00
-
-
Save crizstian/6f7ead5936e1ca2784c1796c2746d69e to your computer and use it in GitHub Desktop.
Example of dependency injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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