Documentation ¶
Index ¶
- func Call(function interface{}, options ...CallOption) ([]interface{}, error)
- func Fill(structure interface{}) error
- func Register(constructor interface{}, options ...Option) error
- func RegisterInstance(interfacePtr interface{}, instance interface{}, options ...Option) error
- func Reset()
- func Resolve(abstraction interface{}, options ...ResolveOption) error
- type CallOption
- type Container
- func (c Container) Call(function interface{}, options ...CallOption) ([]interface{}, error)
- func (c Container) Fill(structure interface{}) error
- func (c Container) Register(constructor interface{}, options ...Option) error
- func (c Container) RegisterInstance(interfacePtr interface{}, instance interface{}, options ...Option) error
- func (c Container) Reset()
- func (c Container) Resolve(abstraction interface{}, options ...ResolveOption) error
- type Option
- type ResolveOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Call ¶
func Call(function interface{}, options ...CallOption) ([]interface{}, error)
Call invoke function that use interface as parameters
func Fill ¶
func Fill(structure interface{}) error
Fill takes a struct and resolves the fields with the tag `optional:"true"` or `name:"dependOnName1"` argument must be a struct point
func Register ¶
Register register interface-> constructor
func RegisterInstance ¶
RegisterInstance register interface->instance into container
func Reset ¶
func Reset()
Reset deletes all the existing bindings and empties the container instance.
func Resolve ¶
func Resolve(abstraction interface{}, options ...ResolveOption) error
Resolve takes an abstraction (interface reference) and fills it with the related implementation.
Types ¶
type CallOption ¶
type CallOption func(*resolveOption) error
func CallArguments ¶
func CallArguments(p map[int]interface{}) CallOption
func CallDependsOn ¶
func CallDependsOn(dependsOn map[int]string) CallOption
CallDependsOn 指定这个构造函数依赖的接口对应的name
type Container ¶
Container interface类型->map["name"]binding对象,如果没有命名实例,那么name就是""
func NewContainer ¶
func NewContainer() Container
NewContainer creates a new instance of the Container
func (Container) Call ¶
func (c Container) Call(function interface{}, options ...CallOption) ([]interface{}, error)
Call takes a function (receiver) with one or more arguments of the abstractions (interfaces). It invokes the function (receiver) and passes the related implementations.
func (Container) Fill ¶
Fill takes a struct and resolves the fields with the tag `optional:"true"` or `name:"dependOnName1"`
func (Container) Register ¶
Register 注册一个对象的构造函数到容器中,该构造函数接收其他interface对象或者值对象作为参数,返回interface对象 注意返回的应该是interface,而不应该是具体的struct类型的指针
func (Container) RegisterInstance ¶
func (c Container) RegisterInstance(interfacePtr interface{}, instance interface{}, options ...Option) error
RegisterInstance 注册一个对象的实例到容器中 参数interfacePtr 是一个接口的指针 参数instance 是实例值
func (Container) Reset ¶
func (c Container) Reset()
Reset deletes all the existing bindings and empties the container instance.
func (Container) Resolve ¶
func (c Container) Resolve(abstraction interface{}, options ...ResolveOption) error
Resolve input interface, resolve instance. 传入接口的指针,获得对应的实例
type Option ¶
type Option func(*binding) error
func Interface ¶
func Interface(it ...interface{}) Option
Interface 指定注册时构造函数返回对象对应的接口指针 比如将Logger这个interface传入,代码为: var l *Logger Interface(l)
func Optional ¶
Optional 指定构造函数中哪些参数是可选的,即使没有Resolve出来,设置为nil即可,也不报错
type ResolveOption ¶
type ResolveOption func(*resolveOption) error
func Arguments ¶
func Arguments(p map[int]interface{}) ResolveOption
Arguments 指定在获得某接口的实例时,该实例构造函数的值
func ResolveName ¶
func ResolveName(name string) ResolveOption
ResolveName 指定在获得接口实例时,使用哪个name对应的构造函数