Socket
Socket
Sign inDemoInstall

di

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    di

Dependency Injection for Node.js. Heavily inspired by AngularJS.


Version published
Weekly downloads
2.4M
decreased by-1.36%
Maintainers
1
Install size
8.01 kB
Created
Weekly downloads
 

Package description

What is di?

The 'di' npm package is a lightweight dependency injection (DI) library for JavaScript and Node.js. It allows developers to manage dependencies in a modular and scalable way, which is particularly useful in large applications or when implementing inversion of control (IoC) patterns.

What are di's main functionalities?

Dependency Registration

This feature allows you to register dependencies with the injector. In the code sample, an API key is registered as a value dependency.

const Injector = require('di');
const injector = new Injector();
injector.value('apiKey', '12345');

Dependency Resolution

This feature involves resolving and injecting dependencies into services or other components. The code sample demonstrates how to resolve a 'MyService' instance with 'apiKey' injected into it.

const Injector = require('di');
const injector = new Injector();
function MyService(apiKey) { this.apiKey = apiKey; }
injector.value('apiKey', '12345');
injector.service('myService', MyService, ['apiKey']);
const myServiceInstance = injector.get('myService');

Child Injectors

Child injectors inherit dependencies from their parent injector but can also override them. This feature is useful for creating isolated scopes.

const Injector = require('di');
const parentInjector = new Injector();
const childInjector = parentInjector.createChild();
parentInjector.value('apiKey', '12345');
childInjector.get('apiKey');

Other packages similar to di

Readme

Source

Dependency Injection for Node.js

Heavily influenced by AngularJS and its implementation of dependency injection. Inspired by Guice and Pico Container.

Keywords

FAQs

Last updated on 03 Apr 2013

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc