go>> di>> 返回
项目作者: ZixiaoWang

项目描述 :
Dependency Injection Module
高级语言: TypeScript
项目地址: git://github.com/ZixiaoWang/di.git
创建时间: 2018-01-11T09:50:53Z
项目社区:https://github.com/ZixiaoWang/di

开源协议:MIT License

下载


DI Module v2

Dependency Injection Module
The module was inspired by di.js in @angular.

Quick Navigate

  1. Decorator
  2. Global Variables
  3. Functions
  4. Interface
  5. Examples
  6. Lisence

Cookbook

Injectable

Use @Injectable() decorator to register class to INJECTABLE_STORE
Otherwise the class cannot be instanized by function instanize

Inject

Use @Inject(...Providers) decorator to inject providers(functions) to class.
The inputed providers will be used to construct instance of decorated class.
NOTE: the sequence of providers is NOT restricted

Component

Use @Component(config: componentConfig) to decorate class.
pass componentConfig to decorator to determine the specific providers for constructing class instance.

bootstrap()

Example: bootstrap({ provider: [...Function] });
This is where intanizing started.
The instanzing function will generate instaces of inputed Providers and store them to INSTANCE_STORE as global instance.

construct(Component)

The function returns an instance which all dependencies has been injected.

instanize(InjectableClass)

The function returns an instance of registered injectable class.

componentConfig

  1. {
  2. restrict?: boolean,
  3. provider: [Function|providerConfig]
  4. }

NOTE: In restrict mode, if the dependency instance cannot be found, it will throw an Error. Otherwise it will return null

providerConfig

  1. {
  2. provider: Function,
  3. useValue?: any,
  4. useClass?: Function,
  5. useExistInstance?: any
  6. }

The priority is useClass > useValue > useExistInstance

Examples

The index.web.js has exposed a global variable DI, use