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

@loke/di-ioc

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loke/di-ioc

Node.js dependency injection.

  • 2.0.1
  • npm
  • Socket score

Version published
Weekly downloads
106
decreased by-6.19%
Maintainers
1
Weekly downloads
 
Created
Source

di-ioc

NPM Version Build Status Coverage Status NPM Downloads License

Dependency injection.

Installation

npm install --save di-ioc

Example

util/index.js

module.exports = require('di-ioc').create()

// Start defining a `random` service:
.define('random', function () {
  var pseudoRandomBytes = require('crypto').pseudoRandomBytes;

  // The `random` service has one function:
  return {
    base64: function () {
      return pseudoRandomBytes(20).toString('base64');
    }
  };
});

app/index.js

module.exports = require('di-ioc').create()

// Greeting service which uses the random service: (arguments are detected)
.define('greet', function (random) {
  return function (name) {
    console.log('Hello ' + name + '! Here is a random string: ' + random.base64());
  };
});

index.js

module.exports = require('di-ioc').create(require)
.use('./util')
.use('./app')

.init();

var randomService = module.exports.util.random;

// eQ/NZnl7qusVN9hB/3nCn3wFKfY=
console.log(randomService.base64());

// Hello World! Here is a random string: dfLGC20CpCJxAZSu+uFp57dlJl0=
module.exports.app.greet();

Features

  • Export to a standard object which automatically initialises dependencies as needed. This is the object .init() creates.
  • Enforce that dependency graph divides into layers. For example, nothing in the 'util' submodule can depend on services in the 'app' submodule, due to the order of definition.
  • Nest components in to hierarchial modules and folders.
  • Instantiate one sub-tree of the hierarchy for testing.
  • Instantiate objects with injected dependencies for unit testing.
  • Define transient objects, using require('di-ioc').create().transient('serviceName', ...);.

FAQs

Package last updated on 03 Oct 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