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

easy-inject

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-inject

A very simple dependency injection library, inspired and mostly borrowed from Angular.

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

Easy Inject

A very simple dependency injection library, inspired and mostly borrowed from Angular.

Installation

npm install --save easy-inject

Usage

Just like in Angular, there are two main ways to use the injection service. One is by declaring them as arguments in your function call. Easy Inject will then parse the argument names and supply the desired dependencies.

var inject = require('easy-inject');

inject(
    function(foo, bar) {
        console.log(foo, bar); // outputs "Hello world!"
    },
    {
        foo: 'Hello ',
        bar: 'world!'
    }
);

Or, you may supply an explicit array of dependencies, and they'll be passed to the function in the same order as specified.

inject(
   ['foo', 'bar', function(a, b) {
       console.log(a, b); // outputs "Hello world!"
   }],
   {
       foo: 'Hello ',
       bar: 'world!'
   }
);

API

Easy Inject exports one simple function which takes two arguments. The first is the function descriptor, which can be either a function, or an explicit array with values of the dependencies and the last element as a function.

The second argument is a dictionary of injectable dependencies.

When using inject, it will annotate the function with it's required dependencies, and it will resolve them by looking up the name in the dictionary of injectable dependencies.

If the dependency cannot be found, an error will be thrown.

Todo

  • Unit tests

Keywords

FAQs

Package last updated on 16 May 2014

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