injector

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagOptionNotRequired = "NR" // Not Required, 标注该字段在执行注入时, 如果没有找到对应的实例, 则忽略该字段
)

Variables

View Source
var (
	NotFoundBucketError        = "未找到对应的 bucket: [%v]"
	NonPointerError            = "无法为非指针类型注入: [%v]"
	NotFoundEntityError        = "[%v] 未找到对应的实例: [%v]; 注入范围: %s; 别名: [%s]"
	InjectionUnfinishedError   = "注入未完成: [%v]"
	InvalidInjectionFiledError = "类型 [%v], 别名: [%s] 值无效"
)

Functions

func Invoke

func Invoke(fn interface{}, opts ...InvokeOption) ([]reflect.Value, error)

func Populate

func Populate(opts ...Option) error

func Provide

func Provide(val IProvider, opts ...Option) error

Types

type Container

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

func New

func New() *Container

func (*Container) Invoke

func (container *Container) Invoke(fn interface{}, opts ...InvokeOption) ([]reflect.Value, error)

func (*Container) Populate

func (container *Container) Populate(opts ...Option) error

func (*Container) Provide

func (container *Container) Provide(val IProvider, opts ...Option) error

func (*Container) Scope

func (container *Container) Scope(name string) *Scope

type IProvider

type IProvider interface {
	Provide(ctx context.Context) any // 为依赖项提供值
}

type InvokeInfo

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

func NewInvokeInfo

func NewInvokeInfo(v interface{}, scope, alias, optional string) *InvokeInfo

type InvokeOption

type InvokeOption func(*InvokeOptions)

func WithInvokeInfo

func WithInvokeInfo(info ...*InvokeInfo) InvokeOption

type InvokeOptions

type InvokeOptions struct {
	InvokeInfo []*InvokeInfo
}

func (*InvokeOptions) GetInvokeInfo

func (i *InvokeOptions) GetInvokeInfo(t reflect.Type) *InvokeInfo

type NameKey

type NameKey struct{}

type Option

type Option func(*Options)

func WithAlias

func WithAlias(alias string) Option

func WithScope

func WithScope(scope string) Option

type Options

type Options struct {
	Alias string
	Scope string
}

type Scope

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

func SubScope

func SubScope(name string) *Scope

func (*Scope) Invoke added in v0.0.8

func (scope *Scope) Invoke(fn interface{}) ([]reflect.Value, error)

func (*Scope) Populate

func (scope *Scope) Populate() error

func (*Scope) Provide

func (scope *Scope) Provide(provider IProvider, option ...Option) error

func (*Scope) Scope

func (scope *Scope) Scope(name string) *Scope

Jump to

Keyboard shortcuts

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