Documentation
¶
Index ¶
- func Fill(dstPtr interface{}, moduleFuncs ...ModuleFunc) error
- func MustFill(dstPtr interface{}, moduleFuncs ...ModuleFunc)
- type Constructor
- type Graph
- type Module
- func (m *Module) AddConstructor(f interface{})
- func (m *Module) AddInstance(instance interface{})
- func (m *Module) AddInstanceWithFields(instance interface{})
- func (m *Module) Import(f ModuleFunc)
- func (m *Module) MarkPackageDep(dep interface{})
- func (m *Module) MarkPackageDeps(structWithDeps interface{})
- type ModuleFunc
- type Package
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fill ¶
func Fill(dstPtr interface{}, moduleFuncs ...ModuleFunc) error
Fill creates a new object graph and fills dstPtr public fields.
func MustFill ¶
func MustFill(dstPtr interface{}, moduleFuncs ...ModuleFunc)
MustFill creates a new object graph and fills dstPtr public fields or panics on an error.
Types ¶
type Constructor ¶
type Constructor struct {
Module *Module
Name string
Type reflect.Type
Deps []reflect.Type
Func func(args []interface{}) interface{}
}
Constructor is a single type specification in a module. It has a result type, dependencies, and a function which returns an instance using an object graph for dependencies.
func (*Constructor) String ¶
func (c *Constructor) String() string
type Graph ¶
Graph is an object graph initialized from a package of modules.
func New ¶
func New(moduleFuncs ...ModuleFunc) (*Graph, error)
New creates a new object graph from module funcs.
func (*Graph) Fill ¶
func (g *Graph) Fill(structPtr interface{})
Fill fills public fields in a struct with instances from this graph.
func (*Graph) MustGet ¶
func (g *Graph) MustGet(i interface{}) interface{}
MustGet returns an instance from this graph of the same type as i.
func (*Graph) MustGetByType ¶
MustGetByType returns an instance from this graph of the given type.
type Module ¶
type Module struct {
Name string
Imports []ModuleFunc
Constructors []*Constructor
PackageDeps []reflect.Type
}
func (*Module) AddConstructor ¶
func (m *Module) AddConstructor(f interface{})
Add adds a new function as a type constructor.
func (*Module) AddInstance ¶
func (m *Module) AddInstance(instance interface{})
AddInstance adds an instance as a constructor.
func (*Module) AddInstanceWithFields ¶
func (m *Module) AddInstanceWithFields(instance interface{})
AddInstanceWithFields adds an instance and all its public fields as constructors.
func (*Module) Import ¶
func (m *Module) Import(f ModuleFunc)
Import imports a module which provides the dependencies of this module.
func (*Module) MarkPackageDep ¶
func (m *Module) MarkPackageDep(dep interface{})
MarkPackageDep adds a dependency which must be resolved at a package level, not via imported modules.
func (*Module) MarkPackageDeps ¶
func (m *Module) MarkPackageDeps(structWithDeps interface{})
MarkPackageDeps adds all struct fields as dependencies which must be resolved at a package level.
type ModuleFunc ¶
type ModuleFunc func(m *Module)
func (ModuleFunc) Name ¶
func (m ModuleFunc) Name() string
type Package ¶
type Package struct {
Modules map[string]*Module
Constructors map[reflect.Type]*Constructor
}
func NewPackage ¶
func NewPackage(moduleFuncs ...ModuleFunc) (*Package, error)