farrow-module
A module abstraction providing dependencies management
#
Installation#
GlossaryModule
:- Any
Class
whichextends Module
- it's a basic unit for writing logic code
- it should not define custom constructor parameters
- it should not be instantiated via the
new
keyword manually - everything it needed is via
this.use(DepClass)
- Any
Provider
- it can be created via
createProvider<Type>(defaultValue)
- it should be attached to
Container
viathis.inject(Provider.provide(value))
- it should be placed only once for a
Container
, duplicated is not allow
- it can be created via
Container
- Any
Class
whichextends Container
- it's the entry of our code of
modules
- it should be instantiated by the
new
keyword
- 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 byProvider
for 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 ofProvider
forContainer
Provider.defaultValue
: thedefaultValue
ofProvider
, it's optional, maybeundefined