Skip to content

Instantly share code, notes, and snippets.

@ceilfors
Last active September 10, 2018 06:16
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 ceilfors/0c36ec007414c2b3a0d16a0a4b2c97df to your computer and use it in GitHub Desktop.
Save ceilfors/0c36ec007414c2b3a0d16a0a4b2c97df to your computer and use it in GitHub Desktop.
better-dependency-injection-with-laconia
const laconia = require("@laconia/core");
// Creates the dependencies
const instances = async () => {
const password = await getPassword();
return { twitterService: new TwitterService(password) };
};
// Declare the dependency you need by destructuring
const handler = ({ twitterService }) => {
return twitterService.getLatestTweets(1000);
};
// Bootstrap laconia
exports.handler = laconia(handler).register(instances);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment