Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@loopback/context

Package Overview
Dependencies
Maintainers
22
Versions
196
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loopback/context

LoopBack's container for Inversion of Control

  • 4.0.0-alpha.13
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
22
Weekly downloads
 
Created
Source

@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

// app level
const app = new Application(); // `app` is a "Context"
app.bind('hello').to('world'); // ContextKey='hello', ContextValue='world'
console.log(app.getSync('hello')); // => 'world'

Dependency injection using context

const Application = require('@loopback/core');
const app = new Application();
app.bind('defaultName').to('John'); // setting context

class HelloController {
  // consider this.ctx here
  constructor(@inject('defaultName') name) { // injecting dependency using context
    this.name = name;
  }
  greet(name) {
    return `Hello ${name || this.name}`;
  }
}

For additional information, please refer to the wiki.

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

Keywords

FAQs

Package last updated on 29 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc