2.4.47 • Published 5 months ago

power-di v2.4.47

Weekly downloads
146
License
MIT
Repository
github
Last release
5 months ago

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.

2.4.47

5 months ago

2.4.46

5 months ago

2.4.43

5 months ago

2.4.42

5 months ago

2.4.45

5 months ago

2.4.44

5 months ago

2.4.39

1 year ago

2.4.38

1 year ago

2.4.41

10 months ago

2.4.40

11 months ago

2.4.36

2 years ago

2.4.37

2 years ago

2.4.35

2 years ago

2.4.34

2 years ago

2.4.19

3 years ago

2.4.29

3 years ago

2.4.28

3 years ago

2.4.25

3 years ago

2.4.24

3 years ago

2.4.27

3 years ago

2.4.26

3 years ago

2.4.21

3 years ago

2.4.20

3 years ago

2.4.23

3 years ago

2.4.22

3 years ago

2.4.32

3 years ago

2.4.31

3 years ago

2.4.33

3 years ago

2.4.30

3 years ago

2.4.18

3 years ago

2.4.17

3 years ago

2.4.16

3 years ago

2.4.15

4 years ago

2.4.14

4 years ago

2.4.13

4 years ago

2.4.10

4 years ago

2.4.12

4 years ago

2.4.11

4 years ago

2.4.9

4 years ago

2.4.8

4 years ago

2.4.6

4 years ago

2.4.5

4 years ago

2.4.4

4 years ago

2.4.3

4 years ago

2.4.3-beta.2

4 years ago

2.4.3-beta

4 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.18

5 years ago

2.3.17

5 years ago

2.3.16

5 years ago

2.3.15

5 years ago

2.3.14

5 years ago

2.3.13

5 years ago

2.3.12

5 years ago

2.3.11

5 years ago

2.3.10

5 years ago

2.3.9

5 years ago

2.3.8

5 years ago

2.3.7

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.10

5 years ago

2.2.9

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.8

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.1

5 years ago

2.2.2

5 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.4.17

6 years ago

1.4.16

7 years ago

1.4.15

7 years ago

1.4.13

7 years ago

1.4.12

7 years ago

1.4.11

7 years ago

1.4.10

7 years ago

1.4.9

7 years ago

1.4.8

7 years ago

1.4.7

7 years ago

1.4.6

7 years ago

1.4.5

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.0

7 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago