@loopback/context
LoopBack uses Context to manage state and dependencies in your application.
Overview
LoopBack implements the concept of a Context to represent a global registry in your application to manage config, state, dependencies, classes, etc. Context also serves as an IoC container used to inject dependencies into your code.
Installation
$ npm install --save @loopback/context
Basic use
const app = new Application();
app.bind('hello').to('world');
console.log(app.getSync('hello'));
Dependency injection using context
const Application = require('@loopback/core');
const app = new Application();
app.bind('defaultName').to('John');
class HelloController {
constructor(@inject('defaultName') private name: string) {
}
greet(name) {
return `Hello ${name || this.name}`;
}
}
For additional information, please refer to the Context page.
Contributions
IBM/StrongLoop is an active supporter of open source and welcomes contributions to our projects as well as those of the Node.js community in general. For more information on how to contribute please refer to the Contribution Guide.
Tests
Run npm test
from the root folder.
Contributors
See all contributors.
License
MIT