1.2.3 • Published 3 years ago

@eryue/injector v1.2.3

Weekly downloads
16
License
MIT
Repository
github
Last release
3 years ago

npm Build Status Coverage Status

a Javascript & Nodejs dependencies injector

  • Container class
import { ContainerClass } from '@eryue/injector';

const initDeps = {
  key: function key() {}
};
const container = new ContainerClass(initDeps);

container.add(class TestService{});

container.resolve(['TestService', 'key'], function(testService, key) {});
// or
const [testService] = container.resolve('TestService');

// this `container.resolve` support various types, eg:
// `container.resolve(string[array<string>[function]])` 
// if argument just is a function, it's arguments would be parsed to be an array to be resolved.
  • Decorator
import { Injectable } from '@eryue/injector';

@Injectable
class TestService {}
  • inject to constructor
import { Inject } from '@eryue/injector';

@Inject('TestService')
class TestControler {
  constructor(testService) {
    this.testService = testService;
  }
}
  • inject to class's function prop
import { Inject } from '@eryue/injector';

class TestControler {
  @Inject('TestService')
  test(testService) {
    // ...
  }
}
  • inject to class's value prop
import { Inject } from '@eryue/injector';

class TestControler {
  @Inject('TestService') testService;
  toString() {
    // this.testService
  }
}
  • when inject to class's function prop, merge injected value and your arguments.
import { Inject } from '@eryue/injector';

class TestControler {
  @Inject('TestService')
  test(testService, yourArguments) {
    // ...
  }
}

new TestControler().test('yourArguments');
1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.1.7

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago