Documentation
¶
Index ¶
- type Closable
- type Container
- func (c *Container) Close()
- func (c *Container) Populate(labelSelector FuncLabelSelector)
- func (c *Container) Provide(objs ...interface{})
- func (c *Container) ProvideByName(name string, obj interface{})
- func (c *Container) ProvideFunc(funcs ...InjectFunc)
- func (c *Container) ProvideFuncByName(name string, ifn InjectFunc)
- type FuncLabelSelector
- type Initializable
- type InjectFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container receive all provided objects and function then inject all of them.
func (*Container) Close ¶ added in v0.4.0
func (c *Container) Close()
Close will call Close method if Closable is implemented. It panics if any error occurs.
func (*Container) Populate ¶
func (c *Container) Populate(labelSelector FuncLabelSelector)
Populate call all provided functions then inject all provided and returned by function objects. It panics if any error occurs. Param labelSelector choice function with it's label. If nil passed, all function will selected. If Initializable is implemented, Init method will be called after object populated.
func (*Container) Provide ¶
func (c *Container) Provide(objs ...interface{})
Provide panics if objs are not pointer to struct or interface.
func (*Container) ProvideByName ¶
ProvideByName panics if name is duplicate. Param name should match other object inject tag like `inject:"Name"`.
func (*Container) ProvideFunc ¶
func (c *Container) ProvideFunc(funcs ...InjectFunc)
ProvideFunc support function types:
- func() T
- func() (T, error)
If use unsupport function as arguments, it will panic. Param label is associated with fn and can be selected. Only selected function will call. If label is empty, by default it is selected.
func (*Container) ProvideFuncByName ¶
func (c *Container) ProvideFuncByName(name string, ifn InjectFunc)
ProvideFuncByName use `name` as object name, panic if name is duplicate.
type FuncLabelSelector ¶
FuncLabelSelector is used to decide a label is selected or not.
type Initializable ¶ added in v0.4.0
type Initializable interface {
Init() error
}
Initializable is optional to implement.
type InjectFunc ¶
type InjectFunc struct {
Fn interface{} // func() T / func() (T, error)
Label string // default selected
Receiver interface{} // *T, receive object from Fn
}
InjectFunc contains a function to new object and label of the function.