Skip to content

Instantly share code, notes, and snippets.

@nfroidure
Created January 26, 2019 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfroidure/c4889b121a3a0146f2af4a7d99cd4a02 to your computer and use it in GitHub Desktop.
Save nfroidure/c4889b121a3a0146f2af4a7d99cd4a02 to your computer and use it in GitHub Desktop.
Another example with service renaming
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