Documentation ¶
Overview ¶
Package inject provides utilities for mapping and injecting dependencies in various ways.
Index ¶
Constants ¶
View Source
const ( InjectTagKey = "inject" InjectTagOptionsOptional = "optional" )
Variables ¶
This section is empty.
Functions ¶
func InterfaceOf ¶
InterfaceOf dereferences a pointer to an Interface type. It panics if value is not an pointer to an interface.
Types ¶
type Applicator ¶
type Applicator interface { // Maps dependencies in the Type map to each field in the struct // that is tagged with 'inject'. Returns an error if the injection // fails. Apply(interface{}) error }
Applicator represents an interface for mapping dependencies to a struct.
type InjectAnnotation ¶ added in v1.0.10
type InjectAnnotation struct { Name string Options TagOptions Exists bool }
func GetInjectAnnotation ¶ added in v1.0.10
func GetInjectAnnotation(structField reflect.StructField) InjectAnnotation
type Injector ¶
type Injector interface { Applicator Invoker TypeMapper // SetParent sets the parent of the injector. If the injector cannot find a // dependency in its Type map it will check its parent before returning an // error. SetParent(Injector) }
Injector represents an interface for mapping and injecting dependencies into structs and function arguments.
func NewLoggerInjector ¶
type Invoker ¶
type Invoker interface { // Invoke attempts to call the interface{} provided as a function, // providing dependencies for function arguments based on Type. Returns // a slice of reflect.Value representing the returned values of the function. // Returns an error if the injection fails. Invoke(interface{}) ([]reflect.Value, error) }
Invoker represents an interface for calling functions via reflection.
type TagOptions ¶ added in v1.0.10
type TagOptions string
func ParseTag ¶ added in v1.0.10
func ParseTag(tag string) (string, TagOptions)
func (TagOptions) Contains ¶ added in v1.0.10
func (o TagOptions) Contains(optionName string) bool
type TypeMapper ¶
type TypeMapper interface { // Maps the interface{} value based on its immediate type from reflect.TypeOf. Map(value interface{}, name string) TypeMapper // Maps the interface{} value based on the pointer of an Interface provided. // This is really only useful for mapping a value as an interface, as interfaces // cannot at this time be referenced directly without a pointer. MapTo(value interface{}, name string, ifacePtr interface{}) TypeMapper // Provides a possibility to directly insert a mapping based on type and value. // This makes it possible to directly map type arguments not possible to instantiate // with reflect like unidirectional channels. Set(typ reflect.Type, name string, value reflect.Value) TypeMapper // Returns the Value that is mapped to the current type. Returns a zeroed Value if // the Type has not been mapped. Get(typ reflect.Type, name string) reflect.Value MapValues(vals ...reflect.Value) error }
TypeMapper represents an interface for mapping interface{} values based on type.
Click to show internal directories.
Click to hide internal directories.