components

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory interface {
	CreateInstance(info Info) (Instance, error)
}

Factory 用于创建组件实例

type Holder

type Holder interface {
	Info() Info
	Factory() Factory
	GetInstance() (Instance, error)
	NewRef(sel Selector) Ref
}

Holder 根据作用域,持有一个或一组组件实例

type ID

type ID string

ID 表示一个组件ID

func (ID) String

func (id ID) String() string

type Info

type Info interface {
	ID() ID
	Aliases() []string
	Classes() []string
	Scope() Scope
}

Info 提供组件的相关信息

type Injection

type Injection interface {
	context.Context

	Select(selector Selector) ([]Instance, error)

	SelectOne(selector Selector) (Instance, error)

	GetByID(id ID) (Instance, error)

	GetApplicationContext() context.Context

	GetProperty(selector Selector) (string, error)

	GetWithHolder(holder Holder) (Instance, error)

	Ext() InjectionExt
}

Injection 表示一个依赖注入上下文

type InjectionExt

type InjectionExt interface {
	Injection() Injection

	GetApplicationContext() context.Context // 返回一个 application.Context

	GetString(selector Selector) string
	GetBool(selector Selector) bool
	GetRune(selector Selector) rune
	GetByte(selector Selector) byte
	GetAny(selector Selector) any

	GetInt(selector Selector) int
	GetInt8(selector Selector) int8
	GetInt16(selector Selector) int16
	GetInt32(selector Selector) int32
	GetInt64(selector Selector) int64

	GetUint(selector Selector) uint
	GetUint8(selector Selector) uint8
	GetUint16(selector Selector) uint16
	GetUint32(selector Selector) uint32
	GetUint64(selector Selector) uint64

	GetFloat32(selector Selector) float32
	GetFloat64(selector Selector) float64

	GetComponent(selector Selector) any

	ListComponents(selector Selector) []any
}

InjectionExt 是 Injection 的扩展部分

type Instance

type Instance interface {
	Ready() bool
	Get() any
	Info() Info
	Inject(i Injection) error
}

Instance 用于创建组件实例

type Ref

type Ref interface {
	Selector() Selector
	Holder() Holder
}

Ref 表示一个对 Holder 的引用

type Registration

type Registration struct {
	ID         ID
	Classes    string // 类名列表,项与项之间以空格符(SPACE)分隔
	Aliases    string // 别名列表,项与项之间以空格符(SPACE)分隔
	Scope      string // 作用域 'singleton'|'prototype'
	NewFunc    func() any
	InjectFunc func(c Injection, instance any) error
}

Registration 组件注册信息

type Registry

type Registry interface {
	New() *Registration
	Register(r *Registration)
}

Registry 提供组件注册服务

type RegistryHandlerFunc

type RegistryHandlerFunc func(r Registry) error

RegistryHandlerFunc 是组件注册的处理函数

type Scope

type Scope int

Scope 表示组件的作用域

const (
	ScopeSingleton Scope = 1
	ScopePrototype Scope = 2
)

定义组件的各种作用域

type Selector

type Selector string

Selector 表示一个组件选择器

func SelectorForAlias

func SelectorForAlias(alias string) Selector

SelectorForAlias 创建 alias 选择器

func SelectorForClass

func SelectorForClass(cname string) Selector

SelectorForClass 创建 class 选择器

func SelectorForID

func SelectorForID(id ID) Selector

SelectorForID 创建 ID 选择器

func (Selector) String

func (sel Selector) String() string

type Table

type Table interface {
	Get(id ID) (Holder, error)
	Put(h Holder) error
	Select(selector Selector) ([]Holder, error)
	ListIDs() []ID
}

Table 表示一个组件的集合

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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