1.0.0 • Published 6 years ago

simple-injector-ts v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

injector

This is a pure injector class.

use

const { Injector } = require('injector')

const injector = new Injector({}) // init dep scope

injector.register('service', () => { // register dep into scope
  return 'service';
});

injector.register('router', () => {
  return 'router';
});

// use dep in code
const doSomething = injector.resolve(
  ['service', 'router'], // the dep used in this function 
  function (hhh) { // main function
    expect(this.service()).toBe('service');
    expect(this.router()).toBe('router');
    expect(hhh).toBe('aaa');
  }, 
  {}, // local scope register
  'aaa' // the other params
);

doSomething();