Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Injector ¶
type Injector struct {
// contains filtered or unexported fields
}
Use the Injector to provide dependency injection (DI) design pattern. The Injector can construct and populate Components (a structs which fields are tagged by `inject: "..."` directive).
The following workflow is suppossed to be done:
- Create an injector by injector := newInjector() call.
- Register components like injector.Register(&Component{comp, "the component name"} ...)
- Do the injection by injector.construct(). Be sure that the call CAN CONSTRUCT components THAT WERE NOT REGISTERED, but refferred by. So, for example, if a Component fields requires injection with empty name tag (`inject:""`) AND there is no registered component with the name (empty), the injector will create a new instance of the refferred component.
- execute the command and shutdown the injector just before exit from the program
The injector supports LifeCycler pattern which allows to initialize components that implement the interface in a specific order and de-initialize them in reverse of the initialization order.
func (*Injector) RegisterMany ¶
func (i *Injector) RegisterMany(comps ...interface{})
func (*Injector) RegisterOne ¶
type LifeCycler ¶
A component can implement the interface when the component has a life-cycle All life-cyclers are ordered by DiPhase value after creation and injection. Components with lower value are initialized first
type PostConstructor ¶
type PostConstructor interface {
DiPostConstruct()
}
A component can implement the interface to be notified by the injector after all dependencies are injected