registry

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const EmbedValue = "embed"
View Source
const InjectTag = "aperture"

Variables

View Source
var EmptyContext = context.Background()
View Source
var TaskDispatcher asynctask.TaskDispatcher = nil
View Source
var UseLazyInject = false

Functions

func AcquireInfrastructure

func AcquireInfrastructure()

func AcquireSingleton

func AcquireSingleton[T any](iface T) T

func AcquireSingletonByName

func AcquireSingletonByName[T any](name string) T

func ContainerProvide

func ContainerProvide[T any](c *Container) (T, bool)

func Inject added in v0.2.7

func Inject[T any](val T) T

Inject is the shortcut for TryInject(val)

func LazyInject added in v0.2.8

func LazyInject()

func Load

func Load[T any](val T) T

Load is a shortcut for TryInject(val) Load will also check if val can add to registry

func MustRegister

func MustRegister[T any](val T, err error) T

func Register

func Register[T any](val T) T

func RegisterConfig

func RegisterConfig(config config.ConfigUnmarshaler)

func RegisterInjectHookFunc added in v0.2.8

func RegisterInjectHookFunc(ifaceName string, hook InjectHookFunc)

func RegisterInjectHooks added in v0.2.8

func RegisterInjectHooks(hooks ...InjectHook)

func RegisterLogger

func RegisterLogger(logger logger.ILogger)

func RegisterSingleton

func RegisterSingleton[T any](singleton interface{})

func RegisterSingletonByName

func RegisterSingletonByName(name string, singleton interface{})

func RegisterTaskDispatcher

func RegisterTaskDispatcher(taskDispatcher asynctask.TaskDispatcher)

func TryInject

func TryInject[T any](injectable T) T

func Use

func Use[T any](val T) T

Use is a function to get instance from registry if val is not nil, then return itself if val is nil, then return the instance from registry

func Validate

func Validate()

func WithLazyInjection added in v0.2.8

func WithLazyInjection(proc func())

WithLazyInjection will do delay inject until all interface registered proc is the function register all interface

Types

type Container

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

func NewContainer

func NewContainer(providers ...Provider[any]) *Container

func (*Container) ContainerName

func (c *Container) ContainerName() string

type Dependency

type Dependency[T any] interface {
	Inject(T)
}

type InjectHook added in v0.2.8

type InjectHook struct {
	Interface string
	Hook      InjectHookFunc
}

type InjectHookFunc added in v0.2.8

type InjectHookFunc func(
	obj reflect.Value,
	field reflect.Value,
	iface string,
	instance *interface{})

InjectHookFunc is a function that is called when a new interface is registered. field is the field that is being injected, and instance is the instance that is being injected, instance can be nil. You can set instance to a new value

type Provider

type Provider[T any] interface {
	Provide() T
}

type Registrant

type Registrant func(impl any)

type Registry

type Registry[I comparable, T any] interface {
	Register(impl T)
	RegisterByEntry(entry I, impl T)
	Acquire(impl T) T
	AcquireByEntry(entry I) T
	AcquireAll() []T
}
var Disposable Registry[int, scene.Disposable]
var Setupable Registry[int, scene.Setupable]

func NewOrderedRegistry

func NewOrderedRegistry[I constraints.Ordered, T any](naming naming[I, T]) Registry[I, T]

func NewRegistry

func NewRegistry[I comparable, T any](naming naming[I, T]) Registry[I, T]

type SingletonProvider

type SingletonProvider[T any] struct {
	// contains filtered or unexported fields
}

func NewSingletonProvider

func NewSingletonProvider[T any](instance T) *SingletonProvider[T]

func (*SingletonProvider[T]) Provide

func (p *SingletonProvider[T]) Provide() T

Jump to

Keyboard shortcuts

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