power-di
A lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use.
Last updated 7 years ago by zhang740 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install power-di 
SYNC missed versions from official npm registry.

Power DI

CI Coverage Version License

A lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use.

Install

npm i power-di --save

Example

a simple example

import { IocContext } from 'power-di';

class AService { }

// default instance, you can also new IocContext to get a instance.
const context = IocContext.DefaultInstance;
context.register(AService);
const aService = context.get(AService); // a instance of AService

inject with key

class AService { }

const context = IocContext.DefaultInstance;
context.register(AService, 'XService'); // key need a string or class, e.g super class or whatever class.
context.get('XService');

use with decorators

const context = new IocContext();

@injectable()
class NRService { }

@injectable()
class LITestService {
  @inject()
  public testService: NRService;
}

const test = context.get(LITestService);

collect impl or extends of some interface/base class

class A { }

@classInfo()
class B extends A { }

@classInfo()
class C extends A { }

@injectable()
class LITestService {
  @imports({ type: A })
  public testService: A[];
}

const test = context.get(LITestService); // test.testService as A[];

use in react

const context = new IocContext;
class NRService { }
context.register(NRService);

class TestComponent extends Component<{}, {}> {
  @inject()
  service: NRService;

  componentDidMount() {
    t.true(this.service instanceof NRService);
  }

  render(): any {
    return null;
  }
}

create(
  <IocProvider context={context}>
    <TestComponent />
  </IocProvider>
);

Class Loader

Power DI introduced the concept of class loader. We can customize the find rule of ioc.

See the test case for details.

Current Tags

  • 3.0.0-alpha.0                                ...           alpha (5 months ago)
  • 2.4.57                                ...           latest (7 months ago)

138 Versions

  • 3.0.0-alpha.0                                ...           5 months ago
  • 2.4.57                                ...           7 months ago
  • 2.4.56                                ...           10 months ago
  • 2.4.55                                ...           a year ago
  • 2.4.54                                ...           a year ago
  • 2.4.53                                ...           a year ago
  • 2.4.52                                ...           a year ago
  • 2.4.51                                ...           a year ago
  • 2.4.50                                ...           a year ago
  • 2.4.49                                ...           a year ago
  • 2.4.48                                ...           a year ago
  • 2.4.47                                ...           2 years ago
  • 2.4.46                                ...           2 years ago
  • 2.4.45                                ...           2 years ago
  • 2.4.44                                ...           2 years ago
  • 2.4.43                                ...           2 years ago
  • 2.4.42                                ...           2 years ago
  • 2.4.41                                ...           2 years ago
  • 2.4.40                                ...           2 years ago
  • 2.4.39                                ...           2 years ago
  • 2.4.38                                ...           2 years ago
  • 2.4.37                                ...           4 years ago
  • 2.4.36                                ...           4 years ago
  • 2.4.35                                ...           4 years ago
  • 2.4.34                                ...           4 years ago
  • 2.4.33                                ...           4 years ago
  • 2.4.32                                ...           4 years ago
  • 2.4.31                                ...           4 years ago
  • 2.4.30                                ...           4 years ago
  • 2.4.29                                ...           4 years ago
  • 2.4.28                                ...           4 years ago
  • 2.4.27                                ...           4 years ago
  • 2.4.26                                ...           4 years ago
  • 2.4.25                                ...           4 years ago
  • 2.4.24                                ...           4 years ago
  • 2.4.23                                ...           4 years ago
  • 2.4.22                                ...           4 years ago
  • 2.4.21                                ...           4 years ago
  • 2.4.20                                ...           4 years ago
  • 2.4.19                                ...           4 years ago
  • 2.4.18                                ...           5 years ago
  • 2.4.17                                ...           5 years ago
  • 2.4.16                                ...           5 years ago
  • 2.4.15                                ...           5 years ago
  • 2.4.14                                ...           5 years ago
  • 2.4.13                                ...           5 years ago
  • 2.4.12                                ...           5 years ago
  • 2.4.11                                ...           5 years ago
  • 2.4.10                                ...           5 years ago
  • 2.4.9                                ...           5 years ago
  • 2.4.8                                ...           5 years ago
  • 2.4.6                                ...           5 years ago
  • 2.4.5                                ...           6 years ago
  • 2.4.4                                ...           6 years ago
  • 2.4.3                                ...           6 years ago
  • 2.4.3-beta.2                                ...           6 years ago
  • 2.4.3-beta                                ...           6 years ago
  • 2.4.2                                ...           6 years ago
  • 2.4.1                                ...           6 years ago
  • 2.4.0                                ...           6 years ago
  • 2.3.18                                ...           6 years ago
  • 2.3.17                                ...           6 years ago
  • 2.3.16                                ...           6 years ago
  • 2.3.15                                ...           6 years ago
  • 2.3.14                                ...           6 years ago
  • 2.3.13                                ...           6 years ago
  • 2.3.12                                ...           6 years ago
  • 2.3.11                                ...           6 years ago
  • 2.3.10                                ...           6 years ago
  • 2.3.9                                ...           6 years ago
  • 2.3.8                                ...           6 years ago
  • 2.3.7                                ...           7 years ago
  • 2.3.6                                ...           7 years ago
  • 2.3.5                                ...           7 years ago
  • 2.3.4                                ...           7 years ago
  • 2.3.3                                ...           7 years ago
  • 2.3.2                                ...           7 years ago
  • 2.3.1                                ...           7 years ago
  • 2.3.0                                ...           7 years ago
  • 2.2.10                                ...           7 years ago
  • 2.2.9                                ...           7 years ago
  • 2.2.8                                ...           7 years ago
  • 2.2.7                                ...           7 years ago
  • 2.2.6                                ...           7 years ago
  • 2.2.5                                ...           7 years ago
  • 2.2.4                                ...           7 years ago
  • 2.2.3                                ...           7 years ago
  • 2.2.2                                ...           7 years ago
  • 2.2.1                                ...           7 years ago
  • 2.2.0                                ...           7 years ago
  • 2.1.1                                ...           7 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.3                                ...           7 years ago
  • 2.0.2                                ...           7 years ago
  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.4.17                                ...           8 years ago
  • 1.4.16                                ...           8 years ago
  • 1.4.15                                ...           8 years ago
  • 1.4.13                                ...           8 years ago
  • 1.4.12                                ...           8 years ago
  • 1.4.11                                ...           8 years ago
  • 1.4.10                                ...           9 years ago
  • 1.4.9                                ...           9 years ago
  • 1.4.8                                ...           9 years ago
  • 1.4.7                                ...           9 years ago
  • 1.4.6                                ...           9 years ago
  • 1.4.5                                ...           9 years ago
  • 1.4.4                                ...           9 years ago
  • 1.4.3                                ...           9 years ago
  • 1.4.2                                ...           9 years ago
  • 1.4.1                                ...           9 years ago
  • 1.4.0                                ...           9 years ago
  • 1.3.5                                ...           9 years ago
  • 1.3.4                                ...           9 years ago
  • 1.3.3                                ...           9 years ago
  • 1.3.2                                ...           9 years ago
  • 1.3.0                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.1                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.8                                ...           10 years ago
  • 1.0.7                                ...           10 years ago
  • 1.0.6                                ...           10 years ago
  • 1.0.5                                ...           10 years ago
  • 1.0.4                                ...           10 years ago
  • 1.0.3                                ...           10 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.0.7                                ...           10 years ago
  • 0.0.6                                ...           10 years ago
  • 0.0.5                                ...           10 years ago
  • 0.0.4                                ...           10 years ago
  • 0.0.3                                ...           10 years ago
  • 0.0.2                                ...           10 years ago
  • 0.0.1                                ...           10 years ago
Maintainers (1)
Downloads
Total 443
Today 0
This Week 4
This Month 326
Last Day 0
Last Week 114
Last Month 3
Dependencies (1)
Dev Dependencies (15)

© 2010 - cnpmjs.org x YWFE | Home | YWFE