Documentation ¶
Overview ¶
Package inject provides a reflect based injector. A large application built with dependency injection in mind will typically involve the boring work of setting up the object graph. This library attempts to take care of this boring work by creating and connecting the various objects. Its use involves you seeding the object graph with some (possibly incomplete) objects, where the underlying types have been tagged for injection. Given this, the library will populate the objects creating new ones as necessary. It uses singletons by default, supports optional private instances as well as named instances.
It works using Go's reflection package and is inherently limited in what it can do as opposed to a code-gen system with respect to private fields.
The usage pattern for the library involves struct tags. It requires the tag format used by the various standard libraries, like json, xml etc. It involves tags in one of the three forms below:
`inject:""` `inject:"private"` `inject:"dev logger"`
The first no value syntax is for the common case of a singleton dependency of the associated type. The second triggers creation of a private instance for the associated type. Finally the last form is asking for a named dependency called "dev logger".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectValue ¶
func InjectValue_ ¶
Types ¶
type AfterInitialize ¶
type AfterInitialize interface {
AfterInitialize()
}
type Graph ¶
type Graph struct { Logger Logger // Optional, will trigger debug logging. // contains filtered or unexported fields }
The Graph of Objects.
type Logger ¶
type Logger interface {
Debugf(format string, v ...interface{})
}
Logger allows for simple logging as inject traverses and populates the object graph.
type Object ¶
type Object struct { Value interface{} Name string // Optional Complete bool // If true, the Value will be considered complete Fields map[string]*Object // Populated with the field names that were injected and their corresponding *Object. // contains filtered or unexported fields }
An Object in the Graph.