container

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

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

func Register(constructor interface{}, options ...Option) error

Register register interface-> constructor

func RegisterInstance

func RegisterInstance(interfacePtr interface{}, instance interface{}, options ...Option) error

RegisterInstance register interface->instance into container

func RegisterSubInterface

func RegisterSubInterface(subInterfacePtr interface{}, interfacePtr interface{}) error

RegisterSubInterface set sub interface map to another interface

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.

func SetDefaultBinding

func SetDefaultBinding(interfacePtr interface{}, defaultName string) error

SetDefaultBinding change default binding to another name

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

type Container struct {
	// contains filtered or unexported fields
}

Container interface类型->map["name"]binding对象,如果没有命名实例,那么name就是""

func Clone

func Clone() *Container

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) Clone

func (c *Container) Clone() *Container

func (*Container) Fill

func (c *Container) Fill(structure interface{}) error

Fill takes a struct and resolves the fields with the tag `optional:"true"` or `name:"dependOnName1"`

func (*Container) Register

func (c *Container) Register(constructor interface{}, options ...Option) error

Register 注册一个对象的构造函数到容器中,该构造函数接收其他interface对象或者值对象作为参数,返回interface对象 注意返回的应该是interface,而不应该是具体的struct类型的指针

func (*Container) RegisterInstance

func (c *Container) RegisterInstance(interfacePtr interface{}, instance interface{}, options ...Option) error

RegisterInstance 注册一个对象的实例到容器中 参数interfacePtr 是一个接口的指针 参数instance 是实例值

func (*Container) RegisterSubInterface

func (c *Container) RegisterSubInterface(subInterfacePtr interface{}, interfacePtr interface{}) error

RegisterSubInterface 注册一个子接口到某个接口

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. 传入接口的指针,获得对应的实例

func (*Container) SetDefaultBinding

func (c *Container) SetDefaultBinding(interfacePtr interface{}, defaultName string) error

type Option

type Option func(*binding) error

func Default

func Default() Option

Default 指定这个接口对应构造函数是不是默认的映射

func DependsOn

func DependsOn(dependsOn map[int]string) Option

DependsOn 指定这个构造函数依赖的接口对应的name

func Interface

func Interface(it ...interface{}) Option

Interface 指定注册时构造函数返回对象对应的接口指针 比如将Logger这个interface传入,代码为: var l *Logger Interface(l)

func Lifestyle

func Lifestyle(isTransient bool) Option

Lifestyle 指定在获得接口对应的实例时,是单例还是临时的

func Name

func Name(name string) Option

Name 指定binding的name

func Optional

func Optional(index ...int) Option

Optional 指定构造函数中哪些参数是可选的,即使没有Resolve出来,设置为nil即可,也不报错

func Parameters

func Parameters(p map[int]interface{}) Option

Parameters 指定这个构造函数的参数值

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对应的构造函数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL