Created
January 26, 2019 11:15
-
-
Save nfroidure/c4889b121a3a0146f2af4a7d99cd4a02 to your computer and use it in GitHub Desktop.
Another example with service renaming
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
import { Knifecycle, constant, autoService, service } from 'knifecycle'; | |
// Initialize the injector | |
const $ = new Knifecycle(); | |
// Declare constants | |
$.register(constant('FTP_CONFIG', { user: 'test', password: 'test' })); | |
$.register(constant('FTP_CONFIG2', { user: 'test2', password: 'test2' })); | |
// Declare services | |
$.register(autoService(async function initFileServer({ FTP_CONFIG }) { | |
let fileServer; | |
// Actual initialization code | |
return fileServer; | |
})); | |
$.register( | |
service(initFileServer, 'fileServer2', ['FTP_CONFIG>FTP_CONFIG2']) | |
); | |
// Initialize root dependencies | |
$.run(['fileServer', 'fileServer2', '$shutdown']) | |
.then(({ fileServer, fileServer2, $shutdown }) => { | |
// Do the actual program work here | |
// Shutdown properly the process | |
return $shutdown(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment