Last active
September 10, 2018 06:16
-
-
Save ceilfors/0c36ec007414c2b3a0d16a0a4b2c97df to your computer and use it in GitHub Desktop.
better-dependency-injection-with-laconia
This file contains 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
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