2.4.37 • Published 1 year ago

power-di v2.4.37

Weekly downloads
146
License
MIT
Repository
github
Last release
1 year 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.36

1 year ago

2.4.37

1 year ago

2.4.35

1 year ago

2.4.34

1 year ago

2.4.19

2 years ago

2.4.29

1 year ago

2.4.28

2 years ago

2.4.25

2 years ago

2.4.24

2 years ago

2.4.27

2 years ago

2.4.26

2 years ago

2.4.21

2 years ago

2.4.20

2 years ago

2.4.23

2 years ago

2.4.22

2 years ago

2.4.32

1 year ago

2.4.31

1 year ago

2.4.33

1 year ago

2.4.30

1 year ago

2.4.18

2 years ago

2.4.17

2 years ago

2.4.16

2 years ago

2.4.15

2 years ago

2.4.14

3 years ago

2.4.13

3 years ago

2.4.10

3 years ago

2.4.12

3 years ago

2.4.11

3 years ago

2.4.9

3 years ago

2.4.8

3 years ago

2.4.6

3 years ago

2.4.5

3 years ago

2.4.4

3 years ago

2.4.3

3 years ago

2.4.3-beta.2

3 years ago

2.4.3-beta

3 years ago

2.4.2

3 years ago

2.4.1

3 years ago

2.4.0

3 years ago

2.3.18

3 years ago

2.3.17

4 years ago

2.3.16

4 years ago

2.3.15

4 years ago

2.3.14

4 years ago

2.3.13

4 years ago

2.3.12

4 years ago

2.3.11

4 years ago

2.3.10

4 years ago

2.3.9

4 years ago

2.3.8

4 years ago

2.3.7

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.10

4 years ago

2.2.9

4 years ago

2.2.7

4 years ago

2.2.6

4 years ago

2.2.8

4 years ago

2.2.5

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.1

4 years ago

2.2.2

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.17

5 years ago

1.4.16

6 years ago

1.4.15

6 years ago

1.4.13

6 years ago

1.4.12

6 years ago

1.4.11

6 years ago

1.4.10

6 years ago

1.4.9

6 years ago

1.4.8

6 years ago

1.4.7

6 years ago

1.4.6

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago