Socket
Socket
Sign inDemoInstall

@aantthony/ioc

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aantthony/ioc

Inversion of control


Version published
Weekly downloads
7
increased by133.33%
Maintainers
1
Install size
17.4 kB
Created
Weekly downloads
 

Readme

Source

ioc

Installation

npm install --save "@aantthony/ioc"

Usage

const ioc = require('@aantthony/ioc');
const createLogger = require('@aantthony/logger');

function createApplication() {
  return ioc({
    log: ioc.transient(module => createLogger(module.name)),
    x() { return 1; },
    y() { return 2; },
    z() { return 3; },
    example(x, y, z) {
      return x + y + z;
    },
    demo(example, log) {
      return {
        run() {
          log.info('Example = ' + example);
        }
      }
    },
    // anotherModule: require('./another-module'),
  });
};

module.exports = createApplication();

// 2017-12-04 11:15:47 demo: Example = 6
createApplication().demo.run();

Built in modules:

module

An object which describes the referring module. NOTE: If a service depends on module, it must be explicitly declared as ioc.transient() as is shown in the above example code.

{ name: 'exampleModule' }

inject

Function which can be used to inject dependencies.

// Executes the function with the dependencies injected.
inject((moduleA, moduleB) => {
  moduleA.doSomething();
  moduleB.doSomethingElse();
});

FAQs

Last updated on 10 Aug 2018

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