Documentation
¶
Index ¶
- Constants
- Variables
- func AcquireInfrastructure()
- func ContainerInject[T any](c *Container, injectable T) T
- func ContainerLoad[T any](c *Container, val T) T
- func ContainerMustRegister[T any](c *Container, val T, err error, name ...string) T
- func ContainerProvide[T any](c *Container, name ...string) T
- func ContainerRegister[T any](c *Container, val T, name ...string) T
- func ContainerUse[T any](c *Container, val T) T
- func Inject[T any](val T) T
- func Load[T any](val T) T
- func MustRegister[T any](val T, err error, name ...string) T
- func Provide[T any](name ...string) T
- func Register[T any](val T, name ...string) T
- func RegisterConfig(cfg config.IConfig)
- func RegisterInjectHookFunc(ifaceName string, hook InjectHookFunc)
- func RegisterInjectHooks(hooks ...InjectHook)
- func RegisterLogger(logger logger.ILogger)
- func RegisterTaskDispatcher(taskDispatcher asynctask.TaskDispatcher)
- func Use[T any](val T) T
- func Validate()
- func WithLazyInjection(proc func())
- type Container
- type InjectHook
- type InjectHookFunc
- type Registrant
- type Registry
Constants ¶
const EmbedValue = "embed"
const InjectTag = "aperture"
const OptionalValue = "optional"
Variables ¶
var Config config.IConfig
var EmptyContext = context.Background()
var Logger logger.ILogger
var TaskDispatcher asynctask.TaskDispatcher = nil
Functions ¶
func AcquireInfrastructure ¶
func AcquireInfrastructure()
func ContainerInject ¶ added in v0.3.7
ContainerInject injects dependencies from c into injectable.
func ContainerLoad ¶ added in v0.3.7
ContainerLoad injects val and registers its lifecycle interfaces without registering val as a dependency.
func ContainerMustRegister ¶ added in v0.3.7
ContainerMustRegister registers val in c or panics when err is non-nil.
func ContainerProvide ¶
func ContainerRegister ¶ added in v0.3.7
ContainerRegister registers and injects a value in c.
func ContainerUse ¶ added in v0.3.7
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 RegisterConfig ¶
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 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 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]
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]