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

di

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

di

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

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6M
decreased by-0.13%
Maintainers
1
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 03 Apr 2013

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