Foundry Service Loader
Get the Code
Usage
1. Require
const FoundryServiceLoader = require('foundry-service-loader');
2. Init
const serviceLoader = FoundryServiceLoader(config);
3. Usage
const myService = new MyService();
serviceLoader.setService('myService', myService);
const serviceLoader = require('foundry-service-loader')();
const myService = serviceLoader.getService('myService');
Included Services
const Config = require('config');
const FoundryServiceLoader = require('foundry-service-loader');
const serviceLoader = FoundryServiceLoader(Config.get('services'))
const elasticSearchClient = serviceLoader.getElasticSearchClient();
return new Promise((resolve, reject) => {
elasticSearchClient.indices.create({
index: 'myIndexName'
}, (err, result) => {
if (err) reject(err);
else resolve(result);
})
})
const Config = require('config');
const FoundryServiceLoader = require('foundry-service-loader');
const serviceLoader = FoundryServiceLoader(Config.get('services'))
const emailService = serviceLoader.getEmailService();
emailService.send(emailData)
.then(authorization => { })
.catch(err => { });
const Config = require('config');
const FoundryServiceLoader = require('foundry-service-loader');
const serviceLoader = FoundryServiceLoader(Config.get('services'))
const logger = serviceLoader.getLogger();
logger.info('My info log', { data })
Making Changes
If you have never used Git, search around online to get a grounding. But here are the basic commands you will need to use to actually push code to our repository, with a little bit of Git theory to explain what's going on.
- First make sure you have the most current version of the codebase. In your terminal window, navigate to the project root. Type
git checkout master
to checkout the master branch. git pull origin master
will update master with any new changes.git checkout -b feature/[NEW_FEATURE_NAME]
this will create a new branch (called feature/NEW_FEATURE_NAME, or whatever you want). Your branch names should be descriptive, but short. For example, if I want to create a cart on my branch, I might call it "feature/cart" (after the object) or "feature/checkout" (after the functionality).- You can run
git branch
at any time to see which branch you're on and what branches you have locally. - Write some code. If you ever want to see which files you've changed, added, or deleted you can run
git status
- When you are satisfied with your changes, make a commit by executing
git commit -am [YOUR_COMMIT_MESSAGE]
. The -a attribute tells Git to commit all changed files. If you don't want to commit all of them, you'll have to type the names of the files. The -m is required; Git needs commit messages. Try to be descriptive, maybe your first commit message will be "store skeleton", the next will be "product page", etc. NOTE git commit -a
will not commit any new files since they are not part of Git yet. If you have new files you will need to run git add .
before the above commands ("." means "all"). - Once the code is committed to your branch, your branch is ready to go. Now we just need to release it into the internet and tell everyone else that we want to combine this branch with the master branch. Execute
git push origin [BRANCH_NAME]
. Here, origin represents our Bitbucket repository. Run git remote -v
to see your repository aliases. - Now we create a pull request on github - in other words, a request to the other developers that we want our code to be merged into the application. In the left sidebar, click Pull Requests > Create Pull Request. The branch on the left should be the branch you were just working on i.e. the one we want to merge into the app. The branch on the right should be master. Make a descriptive title so we know what the pull request is for, and add the necessary reviewers.
- Click "Create Pull Request" and wait for us to review your code.
We follow the git branching model outlined in this blog post
.