Socket
Socket
Sign inDemoInstall

di

Package Overview
Dependencies
19
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    di

A DI framework.


Version published
Maintainers
1
Created

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

Build Status

Dependency Injection v2

This readme describes how to set up your working space in order to run the tests and hack on it. See How can I use it on how to use this DI framework in your project.

Installation

# Clone this repo (or your fork).
git clone https://github.com/angular/di.js.git

# Install all the the dev dependencies, such as Karma, Gulp, etc.
npm install

# If you wanna use "karma" or "gulp" commands, install also:
npm install -g karma-cli
npm install -g gulp

Running the tests

This will start Karma and Chrome (with --harmony enabled). Karma will watch the source code and run the tests anytime you save a change.

karma start

Transpiling ES6

All the source code is written in the upcoming version of JavaScript - ES6. In order to use it in the current browsers you need to transpile the code into ES5 using Traceur.

# Transpile ES6 into ./compiled/*
gulp build

# Watch all the sources and transpile on any change
gulp watch

Examples

gulp build_examples
gulp serve

More stuff

I talked about this DI framework at the ng-conf, here are some more links...

Also, here is the original design doc, which is quickly becoming out-dated ;-)

FAQs

Last updated on 28 Mar 2014

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