registry

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

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

Variables

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

Functions

func AcquireInfrastructure

func AcquireInfrastructure()

func ContainerInject added in v0.3.7

func ContainerInject[T any](c *Container, injectable T) T

ContainerInject injects dependencies from c into injectable.

func ContainerLoad added in v0.3.7

func ContainerLoad[T any](c *Container, val T) T

ContainerLoad injects val and registers its lifecycle interfaces without registering val as a dependency.

func ContainerMustRegister added in v0.3.7

func ContainerMustRegister[T any](c *Container, val T, err error, name ...string) T

ContainerMustRegister registers val in c or panics when err is non-nil.

func ContainerProvide

func ContainerProvide[T any](c *Container, name ...string) T

func ContainerRegister added in v0.3.7

func ContainerRegister[T any](c *Container, val T, name ...string) T

ContainerRegister registers and injects a value in c.

func ContainerUse added in v0.3.7

func ContainerUse[T any](c *Container, val T) T

ContainerUse returns val when it is usable, otherwise it resolves T from c.

func Inject added in v0.2.7

func Inject[T any](val T) T

Inject injects dependencies from the default container into val.

func Load

func Load[T any](val T) T

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

func MustRegister

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

func Provide added in v0.3.7

func Provide[T any](name ...string) T

func Register

func Register[T any](val T, name ...string) T

func RegisterConfig

func RegisterConfig(cfg config.IConfig)

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 RegisterTaskDispatcher

func RegisterTaskDispatcher(taskDispatcher asynctask.TaskDispatcher)

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 proc must perform registration synchronously, and nested calls panic.

Types

type Container

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

func NewContainer

func NewContainer() *Container

func (*Container) RegisterInjectHookFunc added in v0.3.7

func (container *Container) RegisterInjectHookFunc(ifaceName string, hook InjectHookFunc)

func (*Container) RegisterInjectHooks added in v0.3.7

func (container *Container) RegisterInjectHooks(hooks ...InjectHook)

func (*Container) WithLazyInjection added in v0.3.7

func (c *Container) WithLazyInjection(proc func())

WithLazyInjection delays injection in c until proc returns. It must not be nested, and proc must perform registration synchronously.

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 runs during dependency injection when a field is about to be set. It is NOT called during registration.

Parameters:

  • obj: the target object currently being injected (addressable reflect.Value)
  • field: the target field reflect.Value that will receive the dependency
  • iface: the lookup key/name used for this injection (usually interface type string or custom tag)
  • instance: pointer to the resolved dependency instance; hook may replace it before field assignment

If no dependency was resolved, this hook is not executed.

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]

Jump to

Keyboard shortcuts

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