Dependency Injection Module
Dependency Injection Module
The module was inspired by di.js in @angular.
Use @Injectable()
decorator to register class to INJECTABLE_STORE
Otherwise the class cannot be instanized by function instanize
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
Use @Component(config: componentConfig)
to decorate class.
pass componentConfig to decorator to determine the specific providers for constructing class instance.
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.
The function returns an instance which all dependencies has been injected.
The function returns an instance of registered injectable class.
{
restrict?: boolean,
provider: [Function|providerConfig]
}
NOTE: In restrict mode, if the dependency instance cannot be found, it will throw an Error. Otherwise it will return null
{
provider: Function,
useValue?: any,
useClass?: Function,
useExistInstance?: any
}
The priority is useClass > useValue > useExistInstance
The index.web.js has exposed a global variable DI
, use