Documentation
¶
Index ¶
- Constants
- Variables
- func AcquireInfrastructure()
- func AcquireSingleton[T any](iface T) T
- func AcquireSingletonByName[T any](name string) T
- func ContainerProvide[T any](c *Container) (T, bool)
- func Inject[T any](val T) T
- func LazyInject()
- func Load[T any](val T) T
- func MustRegister[T any](val T, err error) T
- func Register[T any](val T) T
- func RegisterConfig(config config.ConfigUnmarshaler)
- func RegisterInjectHookFunc(ifaceName string, hook InjectHookFunc)
- func RegisterInjectHooks(hooks ...InjectHook)
- func RegisterLogger(logger logger.ILogger)
- func RegisterSingleton[T any](singleton interface{})
- func RegisterSingletonByName(name string, singleton interface{})
- func RegisterTaskDispatcher(taskDispatcher asynctask.TaskDispatcher)
- func TryInject[T any](injectable T) T
- func Use[T any](val T) T
- func Validate()
- func WithLazyInjection(proc func())
- type Container
- type Dependency
- type InjectHook
- type InjectHookFunc
- type Provider
- type Registrant
- type Registry
- type SingletonProvider
Constants ¶
View Source
const EmbedValue = "embed"
View Source
const InjectTag = "aperture"
Variables ¶
View Source
var Config config.ConfigUnmarshaler
View Source
var EmptyContext = context.Background()
View Source
var Logger logger.ILogger
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 ContainerProvide ¶
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 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 RegisterSingleton ¶
func RegisterSingleton[T any](singleton interface{})
func RegisterSingletonByName ¶
func RegisterSingletonByName(name string, singleton interface{})
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
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func NewContainer ¶
func (*Container) ContainerName ¶
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 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]
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
Click to show internal directories.
Click to hide internal directories.