injection

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultKey = struct{}{}

Functions

func GetKeyedRoutine

func GetKeyedRoutine[T any](provider IRoutineProvider, key any) T

func GetRoutine

func GetRoutine[T any](provider IRoutineProvider) T

Types

type IRoutineCollection

type IRoutineCollection interface {
	AddDescriptor(descriptor *RoutineDescriptor)
	GetDescriptors() []*RoutineDescriptor
	GetDescriptor(ty reflect.Type) *RoutineDescriptor
	GetKeyedDescriptor(key any, ty reflect.Type) *RoutineDescriptor
}

type IRoutineProvider

type IRoutineProvider interface {
	GetRoutine(ty reflect.Type) any
	GetKeyedRoutine(key any, ty reflect.Type) any

	CreateScope() IRoutineScope
	GetRootScope() IRoutineScope
}

type IRoutineScope

type IRoutineScope interface {
	GetScopedRoutine(ty reflect.Type) any
	GetKeyedScopedRoutine(key any, ty reflect.Type) any
	SetScopedRoutine(ty reflect.Type, value any)
	SetKeyedScopedRoutine(key any, ty reflect.Type, value any)
	GetRoot() IRoutineScope
	GetProvider() IRoutineProvider
}

type RoutineDescriptor

type RoutineDescriptor struct {
	Lifetime RoutineLifetime               // Routine 生命期
	InitLock int32                         // 初始化锁
	Key      any                           // 按 Key 注册
	TyKey    reflect.Type                  // 注册的接口类型 Key
	TyImpl   reflect.Type                  // 注册的实现类型
	Factory  func(scope IRoutineScope) any // 工厂方法,用于在 scope 中创建实例,方法必须返回新实例
}

type RoutineLifetime

type RoutineLifetime uint8
const (
	Singleton RoutineLifetime = iota
	Scoped
	Transient
)

Jump to

Keyboard shortcuts

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