farrow-module
A module abstraction providing dependencies management
Installation#
Glossary#
Module:- Any 
Classwhichextends Module - it's a basic unit for writing logic code
 - it should not define custom constructor parameters
 - it should not be instantiated via the 
newkeyword manually - everything it needed is via 
this.use(DepClass) 
- Any 
 Provider- it can be created via 
createProvider<Type>(defaultValue) - it should be attached to 
Containerviathis.inject(Provider.provide(value)) - it should be placed only once for a 
Container, duplicated is not allow 
- it can be created via 
 Container- Any 
Classwhichextends Container - it's the entry of our code of 
modules - it should be instantiated by the 
newkeyword 
- Any 
 
Usage#
API#
Module#use(DepClass)#
module.use(DepClass) will read or create a DepClass instance from the Container
Module#inject(providerValue)#
module.inject will add provider-value or container to the Container
Module#new(DepClass, options?)#
module.new(DepClass, options) will create a new DepClass instance in current container/context
options.providers, an list of values created byProviderfor injecting/reusing.options.modules, an list of modules for injecting/resuing.
Container.from(Class)#
Container.from(Class) can extends a existed Class make it become a Container which supports this.use() and this.new()
createProvider<Type>(defaultValue?)#
createProvider<Type>(defaultValue?) create a Provider by given Type and defaultValue
Provider.provide(value): create a injectable value ofProviderforContainerProvider.defaultValue: thedefaultValueofProvider, it's optional, maybeundefined